debug move most spew into debug macro

This quietens the spew so all typical debug info now is coming from
the user code (mirror protocol in the sample server / client case).

Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
Andy Green 2011-11-07 19:53:23 +08:00
parent 49146dbcce
commit cc01247c50
6 changed files with 58 additions and 57 deletions

View file

@ -18,7 +18,7 @@ struct libwebsocket * __libwebsocket_client_connect_2(
struct protoent* tcp_proto;
#endif
fprintf(stderr, "__libwebsocket_client_connect_2\n");
debug("__libwebsocket_client_connect_2\n");
wsi->candidate_children_list = NULL;
@ -43,7 +43,7 @@ struct libwebsocket * __libwebsocket_client_connect_2(
* prepare the actual connection (to the proxy, if any)
*/
fprintf(stderr, "__libwebsocket_client_connect_2: address %s", wsi->c_address);
debug("__libwebsocket_client_connect_2: address %s", wsi->c_address);
server_hostent = gethostbyname(wsi->c_address);
if (server_hostent == NULL) {
@ -83,7 +83,7 @@ struct libwebsocket * __libwebsocket_client_connect_2(
goto oom4;
}
fprintf(stderr, "connected\n");
debug("connected\n");
/* into fd -> wsi hashtable */
@ -304,8 +304,7 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
}
if (handled) {
fprintf(stderr, "libwebsocket_client_connect: "
"ext handling conn\n");
debug("libwebsocket_client_connect: ext handling conn\n");
libwebsocket_set_timeout(wsi,
PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE, 5);
@ -314,7 +313,7 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
return wsi;
}
fprintf(stderr, "libwebsocket_client_connect: direct conn\n");
debug("libwebsocket_client_connect: direct conn\n");
return __libwebsocket_client_connect_2(context, wsi);

View file

@ -43,13 +43,13 @@ int lws_extension_callback_deflate_stream(
fprintf(stderr, "deflateInit returned %d\n", n);
return 1;
}
fprintf(stderr, "zlibs constructed\n");
debug("zlibs constructed\n");
break;
case LWS_EXT_CALLBACK_DESTROY:
(void)inflateEnd(&conn->zs_in);
(void)deflateEnd(&conn->zs_out);
fprintf(stderr, "zlibs destructed\n");
debug("zlibs destructed\n");
break;
case LWS_EXT_CALLBACK_PACKET_RX_PREPARSE:

View file

@ -41,7 +41,7 @@ lws_mux_subcommand_header(int cmd, int channel, unsigned char *pb, int len)
unsigned char *start = pb;
if (channel == 0) {
fprintf(stderr, "lws_mux_subcommand_header: given ch 0\n");
muxdebug("lws_mux_subcommand_header: given ch 0\n");
*((int *)0) = 0;
}
@ -91,7 +91,7 @@ static int lws_ext_x_google_mux__send_addchannel(
int n;
if (channel == 0) {
fprintf(stderr, "lws_ext_x_google_mux__send_addchannel: given ch 0\n");
muxdebug("lws_ext_x_google_mux__send_addchannel: given ch 0\n");
*((int *)0) = 0;
}
@ -315,7 +315,7 @@ interpret:
muxdebug("Client LWS_EXT_XGM_STATE__ADDCHANNEL_HEADERS in %c\n", c);
if (conn->block_subchannel == 1) {
fprintf(stderr, "adding ch1\n");
muxdebug("adding ch1\n");
wsi_child = wsi;
child_conn = conn;
} else
@ -379,10 +379,10 @@ interpret:
wsi_child->mode = LWS_CONNMODE_WS_CLIENT;
if (wsi_child->protocol)
fprintf(stderr, "mux handshake OK for protocol %s\n",
muxdebug("mux handshake OK for protocol %s\n",
wsi_child->protocol->name);
else
fprintf(stderr, "mux child handshake ends up with no protocol!\n");
muxdebug("mux child handshake ends up with no protocol!\n");
/*
* inform all extensions, not just active ones since they
@ -576,7 +576,7 @@ bail2:
default:
// fprintf(stderr, " server\n");
if (libwebsocket_rx_sm(wsi_child, c) < 0) {
fprintf(stderr, "probs\n");
muxdebug("probs\n");
libwebsocket_close_and_free_session(
context,
wsi_child,
@ -739,7 +739,7 @@ int lws_extension_callback_x_google_mux(
wsi_parent->candidate_children_list = wsi;
wsi->mode = LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD;
fprintf(stderr, "attaching to existing mux\n");
muxdebug("attaching to existing mux\n");
conn = parent_conn;
wsi = wsi_parent;
@ -757,7 +757,7 @@ int lws_extension_callback_x_google_mux(
if (done)
return 1;
fprintf(stderr, "x-google-mux: unable to mux connection\n");
muxdebug("x-google-mux: unable to mux connection\n");
break;
@ -793,7 +793,7 @@ int lws_extension_callback_x_google_mux(
parent_conn = lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
if (parent_conn == 0) {
fprintf(stderr, "failed to get parent conn\n");
muxdebug("failed to get parent conn\n");
break;
}
}
@ -846,7 +846,7 @@ int lws_extension_callback_x_google_mux(
wsi_parent = conn->wsi_parent;
parent_conn = lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
if (parent_conn == 0) {
fprintf(stderr, "failed to get parent conn\n");
muxdebug("failed to get parent conn\n");
break;
}
for (n = 0; n < parent_conn->highest_child_subchannel; n++)
@ -1048,7 +1048,7 @@ handle_additions:
parent_conn = lws_get_extension_user_matching_ext(conn->wsi_parent, ext);
if (parent_conn == 0) {
fprintf(stderr, "failed to get parent conn\n");
muxdebug("failed to get parent conn\n");
return 0;
}
@ -1133,7 +1133,7 @@ handle_additions:
parent_conn->count_children_needing_POLLOUT++;
muxdebug(" count_children_needing_POLLOUT bumped\n");
} else
fprintf(stderr, "unable to identify parent conn\n");
muxdebug("unable to identify parent conn\n");
}
muxdebug(" requesting on parent %p\n", (void *)conn->wsi_parent);
libwebsocket_callback_on_writable(context, conn->wsi_parent);
@ -1142,7 +1142,8 @@ handle_additions:
case LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX:
fprintf(stderr, "LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX %p\n", (void *)wsi->extension_handles);
muxdebug("LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX %p\n",
(void *)wsi->extension_handles);
/* send raw if we're not a child */
@ -1185,7 +1186,7 @@ handle_additions:
conn->wsi_children[n]->active_extensions_user[m];
if (!child_conn) {
fprintf(stderr, "unable to identify child conn\n");
muxdebug("unable to identify child conn\n");
continue;
}
@ -1209,7 +1210,7 @@ handle_additions:
if (strcmp(in, "deflate-stream") == 0 &&
client_handshake_generation_is_for_mux_child) {
fprintf(stderr, "mux banned deflate-stream on child connection\n");
muxdebug("mux banned deflate-stream on child connection\n");
return 1; /* disallow */
}
break;

View file

@ -349,7 +349,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
*/
c = wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token;
fprintf(stderr, "wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token = %s\n", wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token);
debug("wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token = %s\n", wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token);
wsi->count_active_extensions = 0;
n = 0;
while (more) {
@ -434,7 +434,8 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
wsi->count_active_extensions], NULL, 0);
wsi->count_active_extensions++;
fprintf(stderr, "wsi->count_active_extensions <- %d", wsi->count_active_extensions);
debug("wsi->count_active_extensions <- %d",
wsi->count_active_extensions);
ext++;
}
@ -586,9 +587,9 @@ libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi
if (wsi->parser_state != WSI_PARSING_COMPLETE)
break;
fprintf(stderr, "seem to be serving, mode is %d\n", wsi->mode);
debug("seem to be serving, mode is %d\n", wsi->mode);
fprintf(stderr, "libwebsocket_parse sees parsing complete\n");
debug("libwebsocket_parse sees parsing complete\n");
/* is this websocket protocol or normal http 1.0? */
@ -602,9 +603,8 @@ libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi
return 0;
}
if (!wsi->protocol) {
if (!wsi->protocol)
fprintf(stderr, "NULL protocol coming on libwebsocket_read\n");
}
/*
* It's websocket
@ -695,7 +695,7 @@ libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi
goto bail;
}
fprintf(stderr, "accepted v%02d connection\n",
debug("accepted v%02d connection\n",
wsi->ietf_spec_revision);
break;

View file

@ -187,7 +187,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
*/
if (m) {
fprintf(stderr, "extension vetoed close\n");
debug("extension vetoed close\n");
return;
}
}
@ -252,7 +252,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
if (old_state == WSI_STATE_ESTABLISHED &&
reason != LWS_CLOSE_STATUS_NOSTATUS) {
fprintf(stderr, "sending close indication...\n");
debug("sending close indication...\n");
n = libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING],
0, LWS_WRITE_CLOSE);
@ -269,7 +269,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
libwebsocket_set_timeout(wsi,
PENDING_TIMEOUT_CLOSE_ACK, 5);
fprintf(stderr, "sent close indication, awaiting ack\n");
debug("sent close indication, awaiting ack\n");
return;
}
@ -279,7 +279,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
just_kill_connection:
fprintf(stderr, "libwebsocket_close_and_free_session: just_kill_connection\n");
debug("libwebsocket_close_and_free_session: just_kill_connection\n");
/*
* we won't be servicing or receiving anything further from this guy
@ -316,12 +316,13 @@ just_kill_connection:
((old_state == WSI_STATE_ESTABLISHED) ||
(old_state == WSI_STATE_RETURNED_CLOSE_ALREADY) ||
(old_state == WSI_STATE_AWAITING_CLOSE_ACK))) {
fprintf(stderr, "calling back CLOSED\n");
debug("calling back CLOSED\n");
wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
wsi->user_space, NULL, 0);
} else {
fprintf(stderr, "not calling back closed due to old_state=%d\n", old_state);
}
} else
debug("not calling back closed due to old_state=%d\n",
old_state);
/* deallocate any active extension contexts */
@ -657,7 +658,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
/* no we could add more */
continue;
fprintf(stderr, "choked in POLLOUT service\n");
debug("choked in POLLOUT service\n");
/*
* Yes, he's choked. Leave the POLLOUT masked on so we will
@ -723,7 +724,7 @@ libwebsocket_service_timeout_check(struct libwebsocket_context *context,
*/
if (sec > wsi->pending_timeout_limit) {
fprintf(stderr, "TIMEDOUT WAITING\n");
debug("TIMEDOUT WAITING\n");
libwebsocket_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS);
}
@ -971,7 +972,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
if (n) {
/* an extension vetos us */
fprintf(stderr, "ext %s vetoed\n", (char *)ext->name);
debug("ext %s vetoed\n", (char *)ext->name);
ext++;
continue;
}
@ -1029,7 +1030,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
issue_hdr:
puts(pkt);
// puts(pkt);
/* done with these now */
@ -1080,10 +1081,10 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
!wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len ||
(!wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len &&
wsi->c_protocol != NULL)) {
fprintf(stderr, "libwebsocket_client_handshake "
debug("libwebsocket_client_handshake "
"missing required header(s)\n");
pkt[len] = '\0';
fprintf(stderr, "%s", pkt);
debug("%s", pkt);
goto bail3;
}
@ -1103,7 +1104,7 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
wsi->utf8_token[
WSI_TOKEN_CHALLENGE].token_len);
pkt[len] = '\0';
fprintf(stderr, "%s", pkt);
debug("%s", pkt);
goto bail3;
}
@ -1131,10 +1132,10 @@ lws_client_interpret_server_handshake(struct libwebsocket_context *context,
wsi->ietf_spec_revision == 4) ||
(!wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len &&
wsi->c_protocol != NULL)) {
fprintf(stderr, "libwebsocket_client_handshake "
debug("libwebsocket_client_handshake "
"missing required header(s)\n");
pkt[len] = '\0';
fprintf(stderr, "%s", pkt);
debug("%s", pkt);
goto bail3;
}
@ -1175,7 +1176,7 @@ select_protocol:
if (pc == NULL)
fprintf(stderr, "lws_client_interpret_server_handshake: NULL c_protocol\n");
else
fprintf(stderr, "lws_client_interpret_server_handshake: cPprotocol='%s'\n", pc);
debug("lws_client_interpret_server_handshake: cPprotocol='%s'\n", pc);
/*
* confirm the protocol the server wants to talk was in the list
@ -1248,7 +1249,7 @@ select_protocol:
/* instantiate the accepted extensions */
if (!wsi->utf8_token[WSI_TOKEN_EXTENSIONS].token_len) {
fprintf(stderr, "no client extenstions allowed by server \n");
debug("no client extenstions allowed by server \n");
goto check_accept;
}
@ -1278,7 +1279,7 @@ select_protocol:
/* check we actually support it */
fprintf(stderr, "checking client ext %s\n", ext_name);
debug("checking client ext %s\n", ext_name);
n = 0;
ext = wsi->protocol->owning_server->extensions;
@ -1291,7 +1292,7 @@ select_protocol:
n = 1;
fprintf(stderr, "instantiating client ext %s\n", ext_name);
debug("instantiating client ext %s\n", ext_name);
/* instantiate the extension on this conn */
@ -1532,7 +1533,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
if ((context->protocols[0].callback)(context, wsi,
LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
(void*)(long)accept_fd, NULL, 0)) {
fprintf(stderr, "Callback denied network connection\n");
debug("Callback denied network connection\n");
#ifdef WIN32
closesocket(accept_fd);
#else

View file

@ -110,7 +110,7 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
wsi->utf8_token[wsi->parser_state].token[
wsi->utf8_token[wsi->parser_state].token_len] = '\0';
wsi->parser_state = WSI_TOKEN_SKIPPING_SAW_CR;
fprintf(stderr, "*\n");
debug("*\n");
break;
}
@ -724,7 +724,7 @@ spill:
fprintf(stderr, "seen client close ack\n");
return -1;
}
fprintf(stderr, "server sees client close packet\n");
debug("server sees client close packet\n");
/* parrot the close packet payload back */
n = libwebsocket_write(wsi, (unsigned char *)
&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
@ -1184,7 +1184,7 @@ spill:
* fine he has told us he is closing too, let's
* finish our close
*/
fprintf(stderr, "seen server's close ack\n");
debug("seen server's close ack\n");
return -1;
}
fprintf(stderr, "client sees server close packet len = %d\n", wsi->rx_user_buffer_head);
@ -1220,7 +1220,7 @@ spill:
default:
fprintf(stderr, "Reserved opcode 0x%2X\n", wsi->opcode);
debug("Reserved opcode 0x%2X\n", wsi->opcode);
/*
* It's something special we can't understand here.
* Pass the payload up to the extension's parsing
@ -1510,7 +1510,7 @@ lws_issue_raw_ext_access(struct libwebsocket *wsi,
/* no we could add more */
continue;
fprintf(stderr, "choked\n");
debug("choked\n");
/*
* Yes, he's choked. Don't spill the rest now get a callback