some more ws transport tweaks
This commit is contained in:
parent
cd56d774a0
commit
b2e06346d4
|
@ -1 +1 @@
|
|||
Wed Jun 26 23:10:11 EDT 2013
|
||||
Thu Jun 27 14:04:11 CDT 2013
|
||||
|
|
|
@ -432,26 +432,43 @@ int tport_ws_init_secondary(tport_t *self, int socket, int accepted,
|
|||
int one = 1;
|
||||
tport_ws_primary_t *wspri = (tport_ws_primary_t *)self->tp_pri;
|
||||
tport_ws_t *wstp = (tport_ws_t *)self;
|
||||
char *buffer, *wbuffer;
|
||||
|
||||
self->tp_has_connection = 1;
|
||||
|
||||
if (setsockopt(socket, SOL_TCP, TCP_NODELAY, (void *)&one, sizeof one) == -1)
|
||||
return *return_reason = "TCP_NODELAY", -1;
|
||||
return *return_reason = "TCP_NODELAY", -1;
|
||||
|
||||
#if defined(SO_KEEPALIVE)
|
||||
setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof one);
|
||||
#endif
|
||||
one = 30;
|
||||
#if defined(TCP_KEEPIDLE)
|
||||
setsockopt(socket, SOL_TCP, TCP_KEEPIDLE, (void *)&one, sizeof one);
|
||||
#endif
|
||||
#if defined(TCP_KEEPINTVL)
|
||||
setsockopt(socket, SOL_TCP, TCP_KEEPINTVL, (void *)&one, sizeof one);
|
||||
#endif
|
||||
|
||||
|
||||
if (!accepted)
|
||||
tport_ws_setsndbuf(socket, 64 * 1024);
|
||||
|
||||
if ( wspri->ws_secure ) wstp->ws_secure = 1;
|
||||
|
||||
|
||||
memset(&wstp->ws, 0, sizeof(wstp->ws));
|
||||
if (ws_init(&wstp->ws, socket, 65336, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0) < 0) {
|
||||
|
||||
buffer = (char *) su_alloc((su_home_t *)self, 65536);
|
||||
wbuffer = (char *) su_alloc((su_home_t *)self, 65536);
|
||||
|
||||
if (ws_init(&wstp->ws, socket, buffer, wbuffer, 65336, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0) < 0) {
|
||||
return *return_reason = "WS_INIT", -1;
|
||||
}
|
||||
|
||||
wstp->ws_initialized = 1;
|
||||
self->tp_pre_framed = 1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -352,7 +352,7 @@ issize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes)
|
|||
return r;
|
||||
}
|
||||
|
||||
int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int close_sock)
|
||||
int ws_init(wsh_t *wsh, ws_socket_t sock, char *buffer, char *wbuffer, size_t buflen, SSL_CTX *ssl_ctx, int close_sock)
|
||||
{
|
||||
memset(wsh, 0, sizeof(*wsh));
|
||||
wsh->sock = sock;
|
||||
|
@ -372,9 +372,20 @@ int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int c
|
|||
wsh->buflen = buflen;
|
||||
wsh->secure = ssl_ctx ? 1 : 0;
|
||||
|
||||
if (!wsh->buffer) {
|
||||
if (buffer) {
|
||||
wsh->buffer = buffer;
|
||||
} else if (!wsh->buffer) {
|
||||
wsh->buffer = malloc(wsh->buflen);
|
||||
assert(wsh->buffer);
|
||||
wsh->free_buffer = 1;
|
||||
}
|
||||
|
||||
if (wbuffer) {
|
||||
wsh->wbuffer = wbuffer;
|
||||
} else if (!wsh->wbuffer) {
|
||||
wsh->wbuffer = malloc(wsh->buflen);
|
||||
assert(wsh->wbuffer);
|
||||
wsh->free_wbuffer = 1;
|
||||
}
|
||||
|
||||
if (wsh->secure) {
|
||||
|
@ -454,12 +465,12 @@ void ws_destroy(wsh_t *wsh)
|
|||
wsh->ssl = NULL;
|
||||
}
|
||||
|
||||
if (wsh->buffer) {
|
||||
if (wsh->free_buffer && wsh->buffer) {
|
||||
free(wsh->buffer);
|
||||
wsh->buffer = NULL;
|
||||
}
|
||||
|
||||
if (wsh->wbuffer) {
|
||||
if (wsh->free_wbuffer && wsh->wbuffer) {
|
||||
free(wsh->wbuffer);
|
||||
wsh->wbuffer = NULL;
|
||||
}
|
||||
|
@ -653,13 +664,6 @@ issize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes)
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!wsh->wbuffer) {
|
||||
wsh->wbuffer = malloc(wsh->buflen);
|
||||
assert(wsh->wbuffer);
|
||||
}
|
||||
|
||||
|
||||
memcpy(wsh->wbuffer + wsh->wdatalen, data, bytes);
|
||||
|
||||
wsh->wdatalen += bytes;
|
||||
|
|
|
@ -71,8 +71,9 @@ typedef struct wsh_s {
|
|||
int handshake;
|
||||
uint8_t down;
|
||||
int secure;
|
||||
unsigned close_sock:1;
|
||||
unsigned :0;
|
||||
uint8_t free_buffer;
|
||||
uint8_t free_wbuffer;
|
||||
uint8_t close_sock;
|
||||
} wsh_t;
|
||||
|
||||
issize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
|
||||
|
@ -83,7 +84,7 @@ issize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes);
|
|||
issize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
|
||||
issize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
|
||||
issize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
|
||||
int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int close_sock);
|
||||
int ws_init(wsh_t *wsh, ws_socket_t sock, char *buffer, char *wbuffer, size_t buflen, SSL_CTX *ssl_ctx, int close_sock);
|
||||
issize_t ws_close(wsh_t *wsh, int16_t reason);
|
||||
void ws_destroy(wsh_t *wsh);
|
||||
void init_ssl(void);
|
||||
|
|
Loading…
Reference in New Issue