-Wed Jun 19 12:25:57 CDT 2013
+Thu Jun 20 01:13:57 EDT 2013
tport = nta_incoming_transport(nh->nh_nua->nua_nta, sr->sr_irq, sr->sr_request.msg);
- if (!tport_is_tcp(tport))
- return 0;
+ if (!tport_is_tcp(tport)) {
+ tport_unref(tport);
+ return 0;
+ }
du = nua_dialog_usage_get(ds, nua_registrar_usage, NULL);
if (du == NULL)
tport_unref(ru->tport), ru->tport = NULL;
}
- ru->tport = tport_ref(tport);
+ ru->tport = tport;
ru->pending = tport_pend(tport, NULL, registrar_tport_error, nh);
tport_set_params(tport,
static void tport_ws_deinit_primary(tport_primary_t *pri)
{
tport_ws_primary_t *wspri = (tport_ws_primary_t *)pri;
+
if ( wspri->ssl_ctx ) {
SSL_CTX_free(wspri->ssl_ctx);
wspri->ssl_ctx = NULL;
uint8_t *data;
ws_opcode_t oc;
- if ( !wstp->ws_initialized ) {
+ if (wstp->ws_initialized < 0) {
+ return -1;
+ } else if (wstp->ws_initialized == 0) {
if (ws_init(ws, self->tp_socket, 65336, wstp->ws_secure ? wspri->ssl_ctx : NULL, 0) == -2) {
return 2;
}
return 2;
}
- if ((N == -1000) ||(N == 0)) {
- if (self->tp_msg)
- msg_recv_commit(self->tp_msg, 0, 1);
- return 0; /* End of stream */
+ if ((N == -1000) || (N == 0)) {
+ if (self->tp_msg) {
+ msg_recv_commit(self->tp_msg, 0, 1);
+ }
+ return 0; /* End of stream */
}
if (N < 0) {
- err = su_errno();
+ err = errno = EHOSTDOWN;
SU_DEBUG_1(("%s(%p): su_getmsgsize(): %s (%d)\n", __func__, (void *)self,
su_strerror(err), err));
- return 0;;
+ return 0;
}
veclen = tport_recv_iovec(self, &self->tp_msg, iovec, N, 0);
static void tport_ws_deinit_secondary(tport_t *self)
{
tport_ws_t *wstp = (tport_ws_t *)self;
-
- if (wstp->ws_initialized ) {
- ws_close(wstp->ws, WS_NONE);
- wstp->ws_initialized = 0;
+
+ if (wstp->ws_initialized == 1) {
+ wsh_t *wsh = wstp->ws;
+ SU_DEBUG_1(("%p destroy ws%s transport %p.\n", (void *) self, wstp->ws_secure ? "s" : "", (void *) wsh));
+ ws_destroy(&wsh);
+ wstp->ws_initialized = -1;
}
}
return 0;
}
-issize_t ws_close(wsh_t *wsh, int16_t reason)
+void ws_destroy(wsh_t **wshp)
{
-
- if (wsh->down) {
- return -1;
- }
- wsh->down++;
+ wsh_t *wsh;
- if (reason) {
- uint16_t *u16;
- uint8_t fr[4] = {WSOC_CLOSE | 0x80, 2, 0};
+ if (!wshp || ! *wshp) {
+ return;
+ }
- u16 = (uint16_t *) &fr[2];
- *u16 = htons((int16_t)reason);
- ws_raw_write(wsh, fr, 4);
+ wsh = *wshp;
+ *wshp = NULL;
+
+ if (!wsh->down) {
+ ws_close(wsh, WS_NONE);
}
+ if (wsh->down > 1) {
+ return;
+ }
+
+ wsh->down = 2;
if (wsh->ssl) {
int code;
wsh->ssl = NULL;
}
- if (wsh->close_sock) {
- close(wsh->sock);
- }
-
- wsh->sock = ws_sock_invalid;
-
if (wsh->buffer) {
free(wsh->buffer);
wsh->buffer = NULL;
free(wsh->wbuffer);
wsh->wbuffer = NULL;
}
+}
+
+issize_t ws_close(wsh_t *wsh, int16_t reason)
+{
+
+ if (wsh->down) {
+ return -1;
+ }
+
+ wsh->down = 1;
+
+ if (reason && wsh->sock != ws_sock_invalid) {
+ uint16_t *u16;
+ uint8_t fr[4] = {WSOC_CLOSE | 0x80, 2, 0};
+ u16 = (uint16_t *) &fr[2];
+ *u16 = htons((int16_t)reason);
+ ws_raw_write(wsh, fr, 4);
+ }
+
+ if (wsh->close_sock) {
+ close(wsh->sock);
+ }
+
+ wsh->sock = ws_sock_invalid;
return reason * -1;
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);
issize_t ws_close(wsh_t *wsh, int16_t reason);
+void ws_destroy(wsh_t **wshp);
void init_ssl(void);
void deinit_ssl(void);