1
0
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:
Falk Werner 2019-04-25 20:12:17 +02:00 committed by GitHub
commit 55986aae3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 11 deletions

View File

@ -18,6 +18,11 @@ static int wf_impl_server_protocol_callback(
size_t len)
{
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
if (NULL == ws_protocol)
{
return 0;
}
struct wf_server_protocol * protocol = ws_protocol->user;
wf_impl_timeout_manager_check(&protocol->timeout_manager);

View File

@ -69,7 +69,7 @@ static void wf_impl_session_dispose_filesystems(
while (NULL != item)
{
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);
item = next;
@ -116,7 +116,7 @@ void wf_impl_session_onwritable(
if (!wf_slist_empty(&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);
wf_message_dispose(message);
@ -160,7 +160,7 @@ static struct wf_impl_filesystem * wf_impl_session_get_filesystem(
while (NULL != item)
{
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)
{
result = filesystem;

View File

@ -16,7 +16,7 @@ void wf_impl_session_manager_cleanup(
while (NULL != item)
{
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);
item = next;
@ -51,7 +51,7 @@ struct wf_impl_session * wf_impl_session_manager_get(
while (NULL != item)
{
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)) {
session = current;
@ -72,7 +72,7 @@ void wf_impl_session_manager_remove(
while (NULL != 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)
{
wf_slist_remove_after(&manager->sessions, prev);

View File

@ -7,7 +7,15 @@
#include <cstddef>
#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))
#endif
#endif

View File

@ -9,7 +9,7 @@ void wf_message_queue_cleanup(
while (NULL != item)
{
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);
item = next;
}

View File

@ -101,7 +101,7 @@ static int wfp_impl_client_protocol_callback(
if ((wsi == protocol->wsi) && (!wf_slist_empty(&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);
wf_message_dispose(message);

View File

@ -17,7 +17,7 @@ TEST(ContainerOf, FirstMember)
MyStruct my_struct = {23, 42};
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)
@ -25,5 +25,5 @@ TEST(ContainerOf, SecondMember)
MyStruct my_struct = {23, 42};
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));
}