in c/experimental/raw_plus_tls2.c [508:573]
static bool handle_raw_connection(jabber_connection_t* jc, pn_event_t* event) {
switch (pn_event_type(event)) {
case PN_RAW_CONNECTION_CONNECTED: {
printf("**raw connection established %p %s\n", (void *)jc, jc->is_server ? "server" : "client");
jc->connecting = false;
} break;
case PN_RAW_CONNECTION_NEED_READ_BUFFERS: {
jcheck( buf_unused(&jc->in_wire_buf) );
pn_raw_connection_give_read_buffers(jc->rawc, &jc->in_wire_buf, 1);
buf_set_in_use(&jc->in_wire_buf, true);
} break;
case PN_RAW_CONNECTION_CLOSED_WRITE: {
pn_raw_connection_close(jc->rawc); // In case not fully closed
} break;
case PN_RAW_CONNECTION_WRITTEN:
case PN_RAW_CONNECTION_NEED_WRITE_BUFFERS:
case PN_RAW_CONNECTION_WAKE: {
handle_outgoing(jc);
} break;
case PN_RAW_CONNECTION_CLOSED_READ:
case PN_RAW_CONNECTION_READ: {
handle_incoming(jc, pn_event_type(event) == PN_RAW_CONNECTION_CLOSED_READ);
if (jc->tls_has_output)
handle_outgoing(jc);
} break;
case PN_RAW_CONNECTION_DRAIN_BUFFERS: {
pn_raw_buffer_t rbuf;
while (1 == pn_raw_connection_take_read_buffers(jc->rawc, &rbuf, 1)) {
}
while (1 == pn_raw_connection_take_written_buffers(jc->rawc, &rbuf, 1)) {
}
} break;
case PN_RAW_CONNECTION_DISCONNECTED: {
const char *self = jc->is_server ? "Server" : "Client";
pn_condition_t *cond = pn_raw_connection_condition(jc->rawc);
if (jc->connecting)
printf("**Connection failed\n");
else {
if (!(jc->orderly_close_initiated || jc->orderly_close_detected) || pn_condition_is_set(cond))
printf("**%s connection terminated abnormally\n", self);
else if (jc->orderly_close_detected && jc->parent->current_jline != jlines_count)
printf("**Jabber completed successfully\n", self);
}
if (pn_condition_is_set(cond)) {
fprintf(stderr, "raw connection failure: %s\n", pn_condition_get_name(cond), pn_condition_get_description(cond));
}
if (jc->tls) {
if (jc->need_rawc_write_close)
printf("**%s connection terminated with unsent TLS data\n", self);
tls_cleanup(jc);
}
rbuf_pool_return(&jc->in_wire_buf);
rbuf_pool_return(&jc->out_wire_buf);
free(jc);
} break;
}
return true;
}