/* readcb for bufferevent to check first 24 bytes client connection header. */ static void handshake_readcb(struct bufferevent *bev, void *ptr) { http2_session_data *session_data = (http2_session_data*)ptr; uint8_t data[24]; struct evbuffer *input = bufferevent_get_input(session_data->bev); int readlen = evbuffer_remove(input, data, session_data->handshake_leftlen); const char *conhead = NGHTTP2_CLIENT_CONNECTION_HEADER; if(memcmp(conhead + NGHTTP2_CLIENT_CONNECTION_HEADER_LEN - session_data->handshake_leftlen, data, readlen) != 0) { delete_http2_session_data(session_data); return; } session_data->handshake_leftlen -= readlen; if(session_data->handshake_leftlen == 0) { bufferevent_setcb(session_data->bev, readcb, writecb, eventcb, ptr); /* Process pending data in buffer since they are not notified further */ initialize_nghttp2_session(session_data); if(send_server_connection_header(session_data) != 0) { delete_http2_session_data(session_data); return; } if(session_recv(session_data) != 0) { delete_http2_session_data(session_data); return; } } }
/* readcb for bufferevent after client connection header was checked. */ static void readcb(struct bufferevent *bev, void *ptr) { http2_session_data *session_data = (http2_session_data*)ptr; if(session_recv(session_data) != 0) { delete_http2_session_data(session_data); return; } }
void on_accept(kn_fd_t s,void *ud){ printf("on_accept\n"); kn_proactor_t p = (kn_proactor_t)ud; struct session *session = calloc(1,sizeof(*session)); session->s = s; kn_fd_setud(s,session); kn_proactor_bind(p,s,transfer_finish); session_recv(session); ++client_count; }
void on_accept(handle_t s,void *ud){ printf("on_accept\n"); engine_t p = (engine_t)ud; struct session *session = calloc(1,sizeof(*session)); session->s = s; kn_sock_setud(s,session); kn_sock_associate(s,p,transfer_finish,NULL); session_recv(session); ++client_count; printf("%d\n",client_count); }
static SELECT_RESPONSE_t recv_callback(void *group, int s, uint8_t *data, size_t length, char *addr, uint16_t port, void *param) { options_t *options = (options_t*)param; /* Cleanup - if the buffer is empty, reset it */ if(buffer_get_remaining_bytes(options->buffer) == 0) buffer_clear(options->buffer); buffer_add_bytes(options->buffer, data, length); /* If we have at least a length value */ if(buffer_get_remaining_bytes(options->buffer) >= 2) { /* Read the length. */ uint16_t expected_length = buffer_peek_next_int16(options->buffer); /* Check if we have the full length. */ if(buffer_get_remaining_bytes(options->buffer) - 2 >= expected_length) { uint8_t *data; size_t returned_length; /* Consume the value we already know */ buffer_read_next_int16(options->buffer); /* Read the rest of the buffer. */ data = buffer_read_remaining_bytes(options->buffer, &returned_length, expected_length, TRUE); /* Sanity check. */ assert(expected_length == returned_length); /* Do the callback. */ session_recv(options->session, data, returned_length); /* Free it. */ safe_free(data); /* Clear the buffer if it's empty. */ if(buffer_get_remaining_bytes(options->buffer) == 0) buffer_clear(options->buffer); } } return SELECT_OK; }