static dsk_boolean handle_incoming_connection (DskOctetListener *listener) { DskHttpServerStream *stream; /* accept connection */ switch (dsk_octet_listener_accept (listener, NULL, &source, &sink, &error)) { case DSK_IO_RESULT_SUCCESS: /* create http-server stream */ stream = dsk_http_server_stream_new (sink, source, &server_stream_options); dsk_assert (stream != NULL); dsk_hook_trap (&stream->request_available, (DskHookFunc) handle_http_stream_request_available, stream, dsk_object_unref); break; case DSK_IO_RESULT_AGAIN: break; case DSK_IO_RESULT_ERROR: dsk_main_exit (1); dsk_warning ("cannot accept a new socket: %s", error->message); dsk_error_unref (error); error = NULL; return DSK_FALSE; case DSK_IO_RESULT_EOF: dsk_assert_not_reached (); } /* invoke this handler when the next incoming connection is available. */ return DSK_TRUE; }
static int bio_dsk_bwrite (BIO *bio, const char *out, int length) { DskSslStream *stream = DSK_SSL_STREAM (bio->ptr); DskError *error = NULL; unsigned n_written; BIO_clear_retry_flags (bio); switch (dsk_octet_sink_write (stream->underlying_sink, length, out, &n_written, &error)) { case DSK_IO_RESULT_SUCCESS: return n_written; case DSK_IO_RESULT_EOF: return 0; case DSK_IO_RESULT_AGAIN: BIO_set_retry_write (bio); return -1; case DSK_IO_RESULT_ERROR: dsk_octet_stream_set_error (DSK_OCTET_STREAM (stream), error); dsk_error_unref (error); break; } errno = EINVAL; /* ugh! */ return -1; }
static int bio_dsk_bread (BIO *bio, char *in, int max_length) { DskSslStream *stream = DSK_SSL_STREAM (bio->ptr); DskError *error = NULL; unsigned n_read; BIO_clear_retry_flags (bio); switch (dsk_octet_source_read (stream->underlying_source, max_length, in, &n_read, &error)) { case DSK_IO_RESULT_SUCCESS: return n_read; case DSK_IO_RESULT_EOF: return 0; case DSK_IO_RESULT_AGAIN: BIO_set_retry_read (bio); return -1; case DSK_IO_RESULT_ERROR: dsk_octet_stream_set_error (DSK_OCTET_STREAM (stream), error); dsk_error_unref (error); break; } errno = EINVAL; /* ugh! */ return -1; }
static dsk_boolean handle_underlying_writable (DskOctetSink *underlying, DskSslStream *stream) { dsk_assert (stream->underlying_sink == underlying); if (stream->handshaking) { DskError *error = NULL; if (!do_handshake (stream, &error)) { dsk_octet_stream_set_error (DSK_OCTET_STREAM (stream), error); dsk_error_unref (error); return DSK_FALSE; } return DSK_TRUE; } else if (stream->write_needed_to_read) dsk_hook_notify (&stream->base_instance.source->readable_hook); else dsk_hook_notify (&stream->base_instance.sink->writable_hook); return DSK_TRUE; }