Click here to Skip to main content
15,889,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the following code:
#define Uses_Info
#define Uses_WebSocketServer
#include "ws.h"

int on_connect(WebSocketServer *server);
void on_message(const char *buf);
void on_disconnect();

void* CALLBACK ws_stream_on_connect(WebSocketServer *server)
{
	Info("ws_stream_on_connect");
	int n = 5;
	server->send(server, MESSAGE_TYPE_BINARY, (unsigned char *)&n, sizeof(int));
	Info("after test");
	return server;
	//on_connect(server);
	//return NULL;  // return value is not used in client.
}

size_t CALLBACK ws_stream_on_message(void *plugin_private, const WebSocketServer *server, const int type, unsigned char *buf, const size_t buf_size)
{
	//Info("ws_stream_on_message");
	on_message(buf);
	return 0;
}

void CALLBACK ws_stream_on_disconnect(void *plugin_private, const WebSocketServer *server)
{
	Info("ws_stream_on_disconnect");
	on_disconnect();
}

/*
 * Since we are returning a pointer to static memory, there is no need for a
 * "destroy" function.
 */

static WebSocketPlugin s_plugin = { sizeof(WebSocketPlugin),
                WEBSOCKET_PLUGIN_VERSION_0, NULL, /* destroy */
                ws_stream_on_connect, ws_stream_on_message,
                ws_stream_on_disconnect };

extern EXPORT WebSocketPlugin * CALLBACK ws_stream_init()
{
	Info("ws_stream_init");
    return &s_plugin;
}

I don't get the "after test" log. Info is a function which logs the strings in syslog. I see the "ws_stream_on_connect", but not this one.
What's the problem?
OS is Ubuntu 12.04.

What I have tried:

I tried to see what's logged in apache2 error.log and I also referred to syslog, but nothing is logged there.
Posted
Updated 29-Jul-18 2:01am

Maybe an exception was thrown ? You can wrap the server-> send in a try/catch statement and log a message in the catch block.

BR,
Manfred
 
Share this answer
 
v2
Comments
ilostmyid2 29-Jul-18 3:56am    
yeah i thought it would help, but nothing is logged. it seems that the process is killed abnormally because of a coredump or something
ilostmyid2 29-Jul-18 4:01am    
i think that the functions like ws_stream_on_connect should have "C" signature. so the module is of type .c not .cpp. so i can't use try/catch directly here. but i did it in another cpp module which this function calls it.
oh i found something! in mod_websocket.c, in function handle_websocket_connection, before calling conf->plugin->on_connect which is indeed ws_stream_on_connect, apr_thread_mutex_lock is called on state.mutex. then in mod_websocket_plugin_send we see the lock again. BMO, this means that mod_websocket.c doesn't expect send be called from within ws_stream_on_connect. what do you think?
but, when i see mod_websocket_plugin_send code, i see a section after this lock which indicates that the send may be called from within the main thread! this is where mod_websocket_send_internal is called. how is may be possible?!
for now, i could bypass the problem by creating a thread and sending data from within it. this will be done after ws_stream_on_connect returns.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900