fork-sever-process-and-introduce-broadcast-api.patch
[profile/ivi/libwebsockets.git] / lib / libwebsockets.h
index c1b70e5..b1ae7db 100644 (file)
@@ -26,9 +26,9 @@
 enum libwebsocket_callback_reasons {
        LWS_CALLBACK_ESTABLISHED,
        LWS_CALLBACK_CLOSED,
-       LWS_CALLBACK_SEND,
        LWS_CALLBACK_RECEIVE,
        LWS_CALLBACK_HTTP,
+       LWS_CALLBACK_BROADCAST,
 };
 
 enum libwebsocket_write_protocol {
@@ -38,6 +38,7 @@ enum libwebsocket_write_protocol {
 };
 
 struct libwebsocket;
+struct libwebsocket_context;
 
 /**
  * struct libwebsocket_protocols -     List of protocols and handlers server
@@ -51,6 +52,16 @@ struct libwebsocket;
  *             this much memory allocated on connection establishment and
  *             freed on connection takedown.  A pointer to this per-connection
  *             allocation is passed into the callback in the 'user' parameter
+ * @owning_server:     the server init call fills in this opaque pointer when
+ *             registering this protocol with the server.
+ * @broadcast_socket_port: the server init call fills this in with the
+ *             localhost port number used to forward broadcasts for this
+ *             protocol
+ * @broadcast_socket_user_fd:  the server init call fills this in ... the main()
+ *             process context can write to this socket to perform broadcasts
+ *             (use the libwebsockets_broadcast() api to do this instead,
+ *             it works from any process context)
+ * @protocol_index: which protocol we are starting from zero
  *
  *     This structure represents one protocol supported by the server.  An
  *     array of these structures is passed to libwebsocket_create_server()
@@ -63,10 +74,20 @@ struct libwebsocket_protocols {
                        enum libwebsocket_callback_reasons reason, void *user,
                                                          void *in, size_t len);
        size_t per_session_data_size;
+
+       /*
+        * below are filled in on server init and can be left uninitialized,
+        * no need for user to use them directly either
+        */
+       
+       struct libwebsocket_context *owning_server;
+       int broadcast_socket_port;
+       int broadcast_socket_user_fd;
+       int protocol_index;
 };
 
 extern int libwebsocket_create_server(int port,
-                 const struct libwebsocket_protocols *protocols,
+                 struct libwebsocket_protocols *protocols,
                  const char *ssl_cert_filepath,
                  const char *ssl_private_key_filepath, int gid, int uid);
 
@@ -105,4 +126,13 @@ extern int
 libwebsockets_serve_http_file(struct libwebsocket *wsi, const char *file,
                                                     const char *content_type);
 
+/* notice - you need the pre- and post- padding allocation for buf below */
+
+extern int
+libwebsockets_broadcast(const struct libwebsocket_protocols * protocol,
+                                               unsigned char *buf, size_t len);
+
+extern const struct libwebsocket_protocols *
+libwebsockets_get_protocol(struct libwebsocket *wsi);
+
 #endif