/* Internal callback * called by connection->write_watcher */ static void on_writable(struct ev_loop *loop, ev_io *watcher, int revents) { ebb_connection *connection = watcher->data; ssize_t sent; //printf("on_writable\n"); assert(CONNECTION_HAS_SOMETHING_TO_WRITE); assert(connection->written <= connection->to_write_len); // TODO -- why is this broken? //assert(ev_is_active(&connection->timeout_watcher)); assert(watcher == &connection->write_watcher); if(connection->to_write == 0) goto stop_writing; sent = nosigpipe_push( (void*)(long)connection->fd , connection->to_write + connection->written , connection->to_write_len - connection->written ); if(sent < 0) goto error; if(sent == 0) return; ebb_connection_reset_timeout(connection); connection->written += sent; if(connection->written == connection->to_write_len) { goto stop_writing; } return; stop_writing: ev_io_stop(loop, watcher); connection->to_write = NULL; if(connection->after_write_cb) connection->after_write_cb(connection); return; error: error("close connection on write."); ebb_connection_schedule_close(connection); }
/* Internal callback * called by connection->write_watcher */ static void on_writable(struct ev_loop *loop, ev_io *watcher, int revents) { ebb_connection *connection = watcher->data; ssize_t sent; //printf("on_writable\n"); assert(CONNECTION_HAS_SOMETHING_TO_WRITE); assert(connection->written <= connection->to_write_len); // TODO -- why is this broken? //assert(ev_is_active(&connection->timeout_watcher)); assert(watcher == &connection->write_watcher); if(connection->to_write == 0) goto stop_writing; #ifdef HAVE_GNUTLS assert(!ev_is_active(&connection->handshake_watcher)); if(connection->server->secure) { sent = gnutls_record_send( connection->session , connection->to_write + connection->written , connection->to_write_len - connection->written ); if(sent < 0) { if(gnutls_error_is_fatal(sent)) goto error; if( (sent == GNUTLS_E_INTERRUPTED || sent == GNUTLS_E_AGAIN) && GNUTLS_NEED_READ ) ev_io_stop(loop, watcher); return; } } else { #endif /* HAVE_GNUTLS */ sent = nosigpipe_push( (void*)connection->fd , connection->to_write + connection->written , connection->to_write_len - connection->written ); if(sent < 0) goto error; if(sent == 0) return; #ifdef HAVE_GNUTLS } #endif /* HAVE_GNUTLS */ ebb_connection_reset_timeout(connection); connection->written += sent; if(connection->written == connection->to_write_len) { goto stop_writing; } return; stop_writing: ev_io_stop(loop, watcher); connection->to_write = NULL; if(connection->after_write_cb) connection->after_write_cb(connection); return; error: error("close connection on write."); ebb_connection_schedule_close(connection); }