+/******************* queuing of messages *****************/
+
+/* queue the processing of the received message (except if size=0 cause it's not a valid message) */
+static void queue_message_processing(struct afb_proto_ws *protows, char *data, size_t size, void (*processing)(int,void*))
+{
+ struct binary *binary;
+
+ if (size) {
+ binary = malloc(sizeof *binary);
+ if (!binary) {
+ /* TODO process the problem */
+ errno = ENOMEM;
+ } else {
+ binary->protows = protows;
+ binary->rb.base = data;
+ binary->rb.head = data;
+ binary->rb.end = data + size;
+ if (!protows->queuing
+ || protows->queuing(protows, processing, binary) < 0)
+ processing(0, binary);
+ return;
+ }
+ }
+ free(data);
+}
+
+/******************* sending messages *****************/
+
+static int proto_write(struct afb_proto_ws *protows, struct writebuf *wb)
+{
+ int rc;
+ struct afb_ws *ws;
+
+ pthread_mutex_lock(&protows->mutex);
+ ws = protows->ws;
+ if (ws == NULL) {
+ errno = EPIPE;
+ rc = -1;
+ } else {
+ rc = afb_ws_binary_v(ws, wb->iovec, wb->iovcount);
+ if (rc > 0)
+ rc = 0;
+ }
+ pthread_mutex_unlock(&protows->mutex);
+ return rc;
+}
+