mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
Merge branch 'master' into improve_slist
This commit is contained in:
commit
55986aae3f
@ -18,6 +18,11 @@ static int wf_impl_server_protocol_callback(
|
|||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
|
||||||
|
if (NULL == ws_protocol)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct wf_server_protocol * protocol = ws_protocol->user;
|
struct wf_server_protocol * protocol = ws_protocol->user;
|
||||||
|
|
||||||
wf_impl_timeout_manager_check(&protocol->timeout_manager);
|
wf_impl_timeout_manager_check(&protocol->timeout_manager);
|
||||||
|
@ -69,7 +69,7 @@ static void wf_impl_session_dispose_filesystems(
|
|||||||
while (NULL != item)
|
while (NULL != item)
|
||||||
{
|
{
|
||||||
struct wf_slist_item * next = item->next;
|
struct wf_slist_item * next = item->next;
|
||||||
struct wf_impl_filesystem * filesystem = WF_CONTAINER_OF(item, struct wf_impl_filesystem, item);
|
struct wf_impl_filesystem * filesystem = wf_container_of(item, struct wf_impl_filesystem, item);
|
||||||
wf_impl_filesystem_dispose(filesystem);
|
wf_impl_filesystem_dispose(filesystem);
|
||||||
|
|
||||||
item = next;
|
item = next;
|
||||||
@ -116,7 +116,7 @@ void wf_impl_session_onwritable(
|
|||||||
if (!wf_slist_empty(&session->messages))
|
if (!wf_slist_empty(&session->messages))
|
||||||
{
|
{
|
||||||
struct wf_slist_item * item = wf_slist_remove_first(&session->messages);
|
struct wf_slist_item * item = wf_slist_remove_first(&session->messages);
|
||||||
struct wf_message * message = WF_CONTAINER_OF(item, struct wf_message, item);
|
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||||
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||||
wf_message_dispose(message);
|
wf_message_dispose(message);
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ static struct wf_impl_filesystem * wf_impl_session_get_filesystem(
|
|||||||
while (NULL != item)
|
while (NULL != item)
|
||||||
{
|
{
|
||||||
struct wf_slist_item * next = item->next;
|
struct wf_slist_item * next = item->next;
|
||||||
struct wf_impl_filesystem * filesystem = WF_CONTAINER_OF(item, struct wf_impl_filesystem, item);
|
struct wf_impl_filesystem * filesystem = wf_container_of(item, struct wf_impl_filesystem, item);
|
||||||
if (wsi == filesystem->wsi)
|
if (wsi == filesystem->wsi)
|
||||||
{
|
{
|
||||||
result = filesystem;
|
result = filesystem;
|
||||||
|
@ -16,7 +16,7 @@ void wf_impl_session_manager_cleanup(
|
|||||||
while (NULL != item)
|
while (NULL != item)
|
||||||
{
|
{
|
||||||
struct wf_slist_item * next = item->next;
|
struct wf_slist_item * next = item->next;
|
||||||
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
|
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
||||||
wf_impl_session_dispose(session);
|
wf_impl_session_dispose(session);
|
||||||
|
|
||||||
item = next;
|
item = next;
|
||||||
@ -51,7 +51,7 @@ struct wf_impl_session * wf_impl_session_manager_get(
|
|||||||
while (NULL != item)
|
while (NULL != item)
|
||||||
{
|
{
|
||||||
struct wf_slist_item * next = item->next;
|
struct wf_slist_item * next = item->next;
|
||||||
struct wf_impl_session * current = WF_CONTAINER_OF(item, struct wf_impl_session, item);
|
struct wf_impl_session * current = wf_container_of(item, struct wf_impl_session, item);
|
||||||
|
|
||||||
if (wf_impl_session_contains_wsi(current, wsi)) {
|
if (wf_impl_session_contains_wsi(current, wsi)) {
|
||||||
session = current;
|
session = current;
|
||||||
@ -72,7 +72,7 @@ void wf_impl_session_manager_remove(
|
|||||||
while (NULL != prev->next)
|
while (NULL != prev->next)
|
||||||
{
|
{
|
||||||
struct wf_slist_item * item = prev->next;
|
struct wf_slist_item * item = prev->next;
|
||||||
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
|
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
||||||
if (wsi == session->wsi)
|
if (wsi == session->wsi)
|
||||||
{
|
{
|
||||||
wf_slist_remove_after(&manager->sessions, prev);
|
wf_slist_remove_after(&manager->sessions, prev);
|
||||||
|
@ -7,7 +7,15 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WF_CONTAINER_OF(pointer, type, member) \
|
#ifdef __GNUC__
|
||||||
|
#define wf_container_of(pointer, type, member) \
|
||||||
|
({ \
|
||||||
|
const typeof( ((type *)0)->member ) * __member = (pointer); \
|
||||||
|
(type *)( (char *)__member - offsetof(type, member) ); \
|
||||||
|
})
|
||||||
|
#else
|
||||||
|
#define wf_container_of(pointer, type, member) \
|
||||||
(type *) (((char *) pointer) - offsetof(type, member))
|
(type *) (((char *) pointer) - offsetof(type, member))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,7 +9,7 @@ void wf_message_queue_cleanup(
|
|||||||
while (NULL != item)
|
while (NULL != item)
|
||||||
{
|
{
|
||||||
struct wf_slist_item * next = item->next;
|
struct wf_slist_item * next = item->next;
|
||||||
struct wf_message * message = WF_CONTAINER_OF(item, struct wf_message, item);
|
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||||
wf_message_dispose(message);
|
wf_message_dispose(message);
|
||||||
item = next;
|
item = next;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ static int wfp_impl_client_protocol_callback(
|
|||||||
if ((wsi == protocol->wsi) && (!wf_slist_empty(&protocol->messages)))
|
if ((wsi == protocol->wsi) && (!wf_slist_empty(&protocol->messages)))
|
||||||
{
|
{
|
||||||
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages);
|
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages);
|
||||||
struct wf_message * message = WF_CONTAINER_OF(item, struct wf_message, item);
|
struct wf_message * message = wf_container_of(item, struct wf_message, item);
|
||||||
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
||||||
wf_message_dispose(message);
|
wf_message_dispose(message);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ TEST(ContainerOf, FirstMember)
|
|||||||
MyStruct my_struct = {23, 42};
|
MyStruct my_struct = {23, 42};
|
||||||
|
|
||||||
int * first = &my_struct.first;
|
int * first = &my_struct.first;
|
||||||
ASSERT_EQ(&my_struct, WF_CONTAINER_OF(first, MyStruct, first));
|
ASSERT_EQ(&my_struct, wf_container_of(first, MyStruct, first));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ContainerOf, SecondMember)
|
TEST(ContainerOf, SecondMember)
|
||||||
@ -25,5 +25,5 @@ TEST(ContainerOf, SecondMember)
|
|||||||
MyStruct my_struct = {23, 42};
|
MyStruct my_struct = {23, 42};
|
||||||
|
|
||||||
int * second = &my_struct.second;
|
int * second = &my_struct.second;
|
||||||
ASSERT_EQ(&my_struct, WF_CONTAINER_OF(second, MyStruct, second));
|
ASSERT_EQ(&my_struct, wf_container_of(second, MyStruct, second));
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user