client is now able to send messages

pull/10/head
Falk Werner 6 years ago
parent 1b4a3277b6
commit 95e4d96d79

@ -23,7 +23,6 @@ struct wsfsp_client
struct lws_context_creation_info info; struct lws_context_creation_info info;
struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT]; struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT];
struct lws_context * context; struct lws_context * context;
struct lws * wsi;
}; };
@ -81,7 +80,7 @@ void wsfsp_client_connect(
info.origin = info.address; info.origin = info.address;
info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0; info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0;
info.protocol = WSFSP_PROTOCOL; info.protocol = WSFSP_PROTOCOL;
info.pwsi = &client->wsi; info.pwsi = &client->protocol.wsi;
lws_client_connect_via_info(&info); lws_client_connect_via_info(&info);

@ -16,6 +16,7 @@
#include "wsfs/provider/operation/read_intern.h" #include "wsfs/provider/operation/read_intern.h"
#include "wsfs/util.h" #include "wsfs/util.h"
#include "wsfs/message.h"
static void wsfsp_client_protocol_respond( static void wsfsp_client_protocol_respond(
json_t * response, json_t * response,
@ -81,9 +82,23 @@ static int wsfsp_client_protocol_callback(
case LWS_CALLBACK_CLIENT_RECEIVE: case LWS_CALLBACK_CLIENT_RECEIVE:
wsfsp_client_protocol_process_request(protocol, in, len); wsfsp_client_protocol_process_request(protocol, in, len);
break; break;
case LWS_CALLBACK_CLIENT_WRITEABLE:
{
if ((wsi == protocol->wsi) && (!wsfs_message_queue_empty(&protocol->queue)))
{
struct wsfs_message * message = wsfs_message_queue_pop(&protocol->queue);
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
wsfs_message_dispose(message);
}
}
default: default:
break; break;
} }
if ((wsi == protocol->wsi) && (!wsfs_message_queue_empty(&protocol->queue)))
{
lws_callback_on_writable(wsi);
}
} }
return 0; return 0;
@ -95,6 +110,10 @@ void wsfsp_client_protocol_init(
struct wsfsp_provider const * provider, struct wsfsp_provider const * provider,
void * user_data) void * user_data)
{ {
wsfs_message_queue_init(&protocol->queue);
protocol->wsi = NULL;
protocol->request.respond = &wsfsp_client_protocol_respond; protocol->request.respond = &wsfsp_client_protocol_respond;
protocol->request.user_data = protocol; protocol->request.user_data = protocol;
@ -113,7 +132,7 @@ void wsfsp_client_protocol_init(
void wsfsp_client_protocol_cleanup( void wsfsp_client_protocol_cleanup(
struct wsfsp_client_protocol * protocol) struct wsfsp_client_protocol * protocol)
{ {
(void) protocol; wsfs_message_queue_cleanup(&protocol->queue);
} }
struct wsfsp_client_protocol * wsfsp_client_protocol_create( struct wsfsp_client_protocol * wsfsp_client_protocol_create(

@ -5,11 +5,15 @@
#include "wsfs/provider/provider.h" #include "wsfs/provider/provider.h"
#include "wsfs/provider/request.h" #include "wsfs/provider/request.h"
#include "wsfs/message_queue.h"
struct wsfsp_client_protocol struct wsfsp_client_protocol
{ {
struct wsfsp_request request; struct wsfsp_request request;
struct wsfsp_provider provider; struct wsfsp_provider provider;
void * user_data; void * user_data;
struct lws * wsi;
struct wsfs_message_queue queue;
}; };
#ifdef __cplusplus #ifdef __cplusplus

Loading…
Cancel
Save