Skip to content

Commit

Permalink
sync to master of libwebsockets, commit : 6c58228
Browse files Browse the repository at this point in the history
And fix client header of Origin, add prefix "http://" to make a valid URI, to make golang websocket server happy.
  • Loading branch information
u0u0 committed Aug 28, 2013
1 parent 482c279 commit b0bb0a7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/client-handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct libwebsocket *__libwebsocket_client_connect_2(

if (context->http_proxy_port) {

n = send(wsi->sock, context->service_buffer, plen, 0);
n = send(wsi->sock, context->service_buffer, plen, MSG_NOSIGNAL);
if (n < 0) {
compatible_close(wsi->sock);
lwsl_debug("ERROR writing to proxy socket\n");
Expand Down
4 changes: 2 additions & 2 deletions lib/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ int lws_client_socket_service(struct libwebsocket_context *context,
else
#endif
n = send(wsi->sock, context->service_buffer,
p - (char *)context->service_buffer, 0);
p - (char *)context->service_buffer, MSG_NOSIGNAL);
lws_latency(context, wsi,
"send or SSL_write LWS_CONNMODE...HANDSHAKE",
n, n >= 0);
Expand Down Expand Up @@ -774,7 +774,7 @@ libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
p += strlen(key_b64);
p += sprintf(p, "\x0d\x0a");
if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN))
p += sprintf(p, "Origin: %s\x0d\x0a",
p += sprintf(p, "Origin: http://%s\x0d\x0a",
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN));

if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS))
Expand Down
6 changes: 6 additions & 0 deletions lib/libwebsockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
lwsl_debug("closing http fd %d\n", wsi->u.http.fd);
close(wsi->u.http.fd);
wsi->u.http.fd = 0;
context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
}

#ifndef LWS_NO_EXTENSIONS
Expand Down Expand Up @@ -368,6 +370,10 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context,
lwsl_debug("calling back CLOSED\n");
wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
wsi->user_space, NULL, 0);
} else if ( wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED ) {
lwsl_debug("calling back CLOSED_HTTP\n");
context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0 );
} else
lwsl_debug("not calling back closed\n");

Expand Down
3 changes: 3 additions & 0 deletions lib/libwebsockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ enum libwebsocket_callback_reasons {
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
LWS_CALLBACK_CLIENT_ESTABLISHED,
LWS_CALLBACK_CLOSED,
LWS_CALLBACK_CLOSED_HTTP,
LWS_CALLBACK_RECEIVE,
LWS_CALLBACK_CLIENT_RECEIVE,
LWS_CALLBACK_CLIENT_RECEIVE_PONG,
Expand Down Expand Up @@ -419,6 +420,8 @@ struct libwebsocket_extension;
*
* LWS_CALLBACK_CLOSED: when the websocket session ends
*
* LWS_CALLBACK_CLOSED_HTTP: when a HTTP (non-websocket) session ends
*
* LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a
* remote client, it can be found at *in and is
* len bytes long
Expand Down
15 changes: 7 additions & 8 deletions lib/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
int m;
#endif

if (len == 0 && protocol != LWS_WRITE_CLOSE) {
if (len == 0 && protocol != LWS_WRITE_CLOSE && protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) {
lwsl_warn("zero length libwebsocket_write attempt\n");
return 0;
}
Expand Down Expand Up @@ -504,7 +504,6 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
struct libwebsocket_context *context, struct libwebsocket *wsi)
{
int ret = 0;
int n, m;

while (!lws_send_pipe_choked(wsi)) {
Expand All @@ -516,7 +515,7 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
if (m < 0)
return -1;

wsi->u.http.filepos += n;
wsi->u.http.filepos += m;
if (m != n)
/* adjust for what was not sent */
lseek(wsi->u.http.fd, m - n, SEEK_CUR);
Expand All @@ -525,23 +524,23 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment(
if (n < 0)
return -1; /* caller will close */

if (n < sizeof(context->service_buffer) ||
wsi->u.http.filepos == wsi->u.http.filelen) {
if (wsi->u.http.filepos == wsi->u.http.filelen) {
wsi->state = WSI_STATE_HTTP;

if (wsi->protocol->callback)
ret = user_callback_handle_rxflow(
/* ignore callback returned value */
user_callback_handle_rxflow(
wsi->protocol->callback, context, wsi,
LWS_CALLBACK_HTTP_FILE_COMPLETION,
wsi->user_space, NULL, 0);
return ret;
return 1; /* >0 indicates completed */
}
}

lwsl_notice("choked before able to send whole file (post)\n");
libwebsocket_callback_on_writable(context, wsi);

return ret;
return 0; /* indicates further processing must be done */
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/sha-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ sha1_step(struct sha1_ctxt *ctxt)

/*------------------------------------------------------------*/

void
static void
sha1_init(struct sha1_ctxt *ctxt)
{
bzero(ctxt, sizeof(struct sha1_ctxt));
Expand Down

0 comments on commit b0bb0a7

Please sign in to comment.