GNU libmicrohttpd
0.9.29
|
TCP connection/SPDY session handling. So far most of the functions for handling SPDY framing layer are here. More...
#include "platform.h"
#include "structures.h"
#include "internal.h"
#include "session.h"
#include "compression.h"
#include "stream.h"
#include "io.h"
Go to the source code of this file.
TCP connection/SPDY session handling. So far most of the functions for handling SPDY framing layer are here.
Definition in file session.c.
void SPDYF_handler_ignore_frame | ( | struct SPDY_Session * | session | ) |
Carefully ignore the full size of frames which are not yet supported by the lib. TODO Ignoring frames containing compressed bodies means that the compress state will be corrupted on next received frame. According to the draft the lib SHOULD try to decompress data also in corrupted frames just to keep right compression state.
session | SPDY_Session whose read buffer is used. |
Definition at line 828 of file session.c.
References SPDY_Session::frame_handler_cls, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_MAX_SUPPORTED_FRAME_SIZE, SPDY_SESSION_STATUS_IGNORE_BYTES, SPDY_SESSION_STATUS_WAIT_FOR_BODY, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER, SPDYF_ASSERT, and SPDY_Session::status.
Referenced by SPDYF_session_idle(), and SPDYF_stream_new().
|
static |
Handler for reading DATA frames. In requests they are used for POST arguments.
session | SPDY_Session whose read buffer is used. |
Definition at line 330 of file session.c.
References SPDY_Daemon::cls, SPDY_Session::daemon, SPDY_Session::frame_handler_cls, SPDY_Daemon::freceived_data_cb, SPDYF_Stream::is_in_closed, NULL, SPDY_Session::read_buffer, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_Daemon::received_data_cb, SPDY_DATA_FLAG_FIN, SPDY_MAX_SUPPORTED_FRAME_SIZE, SPDY_SESSION_STATUS_IGNORE_BYTES, SPDY_SESSION_STATUS_WAIT_FOR_BODY, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER, SPDY_YES, SPDYF_ASSERT, SPDYF_DEBUG, SPDYF_INITIAL_WINDOW_SIZE, SPDYF_prepare_window_update(), SPDYF_stream_find(), SPDY_Session::status, and SPDYF_Stream::window_size.
Referenced by SPDYF_session_idle(), and SPDYF_session_read().
|
static |
Handler for reading the GOAWAY frame after we know that the frame is such. The function waits for the full frame and then changes status of the session.
session | SPDY_Session whose read buffer is used. |
Definition at line 179 of file session.c.
References SPDY_Session::frame_handler_cls, SPDY_Session::is_goaway_received, NTOH31, SPDY_Session::read_buffer, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_GOAWAY_STATUS_INTERNAL_ERROR, SPDY_GOAWAY_STATUS_OK, SPDY_GOAWAY_STATUS_PROTOCOL_ERROR, SPDY_MAX_SUPPORTED_FRAME_SIZE, SPDY_SESSION_STATUS_IGNORE_BYTES, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER, SPDYF_ASSERT, SPDYF_DEBUG, and SPDY_Session::status.
Referenced by SPDYF_session_idle().
|
static |
Handler for reading RST_STREAM frames. After receiving the frame the stream moves into closed state and status of the session is changed. Frames, belonging to this stream, which are still at the output queue, will be ignored later.
session | SPDY_Session whose read buffer is used. |
Definition at line 258 of file session.c.
References SPDY_Session::frame_handler_cls, SPDYF_Stream::is_in_closed, SPDYF_Stream::is_out_closed, SPDYF_Stream::next, NTOH31, NULL, SPDY_Session::read_buffer, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_SESSION_STATUS_IGNORE_BYTES, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER, SPDYF_ASSERT, SPDYF_DEBUG, SPDY_Session::status, SPDYF_Stream::stream_id, and SPDY_Session::streams_head.
Referenced by SPDYF_session_idle().
|
static |
Handler for reading the full SYN_STREAM frame after we know that the frame is such. The function waits for the full frame and then changes status of the session. New stream is created.
session | SPDY_Session whose read buffer is used. |
Definition at line 44 of file session.c.
References SPDY_Session::current_stream_id, SPDY_Session::daemon, SPDY_Daemon::fcls, SPDY_Daemon::fnew_stream_cb, SPDY_Session::frame_handler_cls, SPDYF_Stream::headers, NULL, SPDY_Session::read_buffer, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_GOAWAY_STATUS_INTERNAL_ERROR, SPDY_MAX_SUPPORTED_FRAME_SIZE, SPDY_NO, SPDY_RST_STREAM_STATUS_PROTOCOL_ERROR, SPDY_SESSION_STATUS_FLUSHING, SPDY_SESSION_STATUS_IGNORE_BYTES, SPDY_SESSION_STATUS_WAIT_FOR_BODY, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER, SPDY_YES, SPDYF_ASSERT, SPDYF_DEBUG, SPDYF_name_value_from_stream(), SPDYF_prepare_goaway(), SPDYF_prepare_rst_stream(), SPDYF_stream_new(), SPDYF_zlib_inflate(), SPDY_Session::status, SPDYF_Stream::stream_id, SPDY_Session::streams_head, and SPDY_Session::zlib_recv_stream.
Referenced by SPDYF_session_idle().
int SPDYF_handler_write_data | ( | struct SPDY_Session * | session | ) |
Handler called by session_write to fill the write buffer according to the data frame waiting in the response queue. When response data is given by user callback, the lib does not know how many frames are needed. In such case this call produces another ResponseQueue object and puts it on the queue while the the user callback says that there will be more data.
Definition at line 568 of file session.c.
References SPDYF_Response_Queue::data, SPDYF_Response_Queue::data_frame, SPDYF_Response_Queue::frqcb, SPDYF_Response_Queue::frqcb_cls, SPDYF_Response_Queue::next, NULL, SPDYF_Response_Queue::prev, SPDY_Response::rcb, SPDY_Response::rcb_block_size, SPDY_Response::rcb_cls, SPDYF_Response_Queue::response, SPDY_Session::response_queue_head, SPDY_Session::response_queue_tail, SPDYF_Response_Queue::rrcb, SPDYF_Response_Queue::rrcb_cls, SPDY_DATA_FLAG_FIN, SPDY_NO, SPDY_RST_STREAM_STATUS_INTERNAL_ERROR, SPDY_SESSION_STATUS_CLOSING, SPDY_YES, SPDYF_ASSERT, SPDYF_DATA_FRAME_HTON, SPDYF_prepare_rst_stream(), SPDYF_response_queue_create(), SPDY_Session::status, SPDYF_Response_Queue::stream, SPDY_Session::write_buffer, SPDY_Session::write_buffer_beginning, SPDY_Session::write_buffer_offset, and SPDY_Session::write_buffer_size.
Referenced by SPDYF_response_queue_create().
int SPDYF_handler_write_goaway | ( | struct SPDY_Session * | session | ) |
Handler called by session_write to fill the write buffer based on the control frame (GOAWAY) waiting in the response queue.
session | SPDY session |
Definition at line 515 of file session.c.
References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, HTON31, SPDY_Session::is_goaway_sent, SPDY_Session::last_replied_to_stream_id, NULL, SPDY_Session::response_queue_head, SPDY_NO, SPDY_YES, SPDYF_ASSERT, SPDYF_CONTROL_FRAME_HTON, SPDY_Session::write_buffer, SPDY_Session::write_buffer_beginning, SPDY_Session::write_buffer_offset, and SPDY_Session::write_buffer_size.
Referenced by SPDYF_prepare_goaway().
int SPDYF_handler_write_rst_stream | ( | struct SPDY_Session * | session | ) |
Handler called by session_write to fill the write buffer based on the control frame (RST_STREAM) waiting in the response queue.
session | SPDY session |
Definition at line 740 of file session.c.
References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, NULL, SPDY_Session::response_queue_head, SPDY_NO, SPDY_YES, SPDYF_ASSERT, SPDYF_CONTROL_FRAME_HTON, SPDY_Session::write_buffer, SPDY_Session::write_buffer_beginning, SPDY_Session::write_buffer_offset, and SPDY_Session::write_buffer_size.
Referenced by SPDYF_prepare_rst_stream().
int SPDYF_handler_write_syn_reply | ( | struct SPDY_Session * | session | ) |
Handler called by session_write to fill the write buffer based on the control frame (SYN_REPLY) waiting in the response queue.
session | SPDY session |
Definition at line 420 of file session.c.
References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, SPDYF_Response_Queue::data_size, HTON31, SPDY_Session::last_replied_to_stream_id, NULL, SPDY_Session::response_queue_head, SPDY_NO, SPDY_SESSION_STATUS_CLOSING, SPDY_YES, SPDYF_ASSERT, SPDYF_CONTROL_FRAME_HTON, SPDYF_zlib_deflate(), SPDY_Session::status, SPDYF_Response_Queue::stream, SPDYF_Stream::stream_id, SPDY_Session::write_buffer, SPDY_Session::write_buffer_beginning, SPDY_Session::write_buffer_offset, SPDY_Session::write_buffer_size, and SPDY_Session::zlib_send_stream.
Referenced by SPDYF_response_queue_create().
int SPDYF_handler_write_window_update | ( | struct SPDY_Session * | session | ) |
Handler called by session_write to fill the write buffer based on the control frame (WINDOW_UPDATE) waiting in the response queue.
session | SPDY session |
Definition at line 785 of file session.c.
References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, NULL, SPDY_Session::response_queue_head, SPDY_NO, SPDY_YES, SPDYF_ASSERT, SPDYF_CONTROL_FRAME_HTON, SPDY_Session::write_buffer, SPDY_Session::write_buffer_beginning, SPDY_Session::write_buffer_offset, and SPDY_Session::write_buffer_size.
Referenced by SPDYF_prepare_window_update().
int SPDYF_prepare_goaway | ( | struct SPDY_Session * | session, |
enum SPDY_GOAWAY_STATUS | status, | ||
bool | in_front | ||
) |
Prepares GOAWAY frame to tell the client to stop creating new streams. The session should be closed soon after this call.
session | SPDY session |
status | code for the GOAWAY frame |
in_front | whether or not to put the frame in front of everything on the response queue |
Definition at line 1615 of file session.c.
References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, SPDYF_Response_Queue::data_size, NULL, SPDYF_Response_Queue::process_response_handler, SPDY_CONTROL_FRAME_TYPES_GOAWAY, SPDY_NO, SPDY_VERSION, SPDY_YES, SPDYF_handler_write_goaway(), and SPDYF_queue_response().
Referenced by spdyf_close_all_sessions(), spdyf_handler_read_syn_stream(), SPDYF_session_idle(), SPDYF_session_read(), and SPDYF_session_write().
int SPDYF_prepare_rst_stream | ( | struct SPDY_Session * | session, |
struct SPDYF_Stream * | stream, | ||
enum SPDY_RST_STREAM_STATUS | status | ||
) |
Prepares RST_STREAM frame to terminate a stream. This frame may or not indicate an error. The frame will be put at the head of the queue. This means that frames for this stream which are still in the queue will be discarded soon.
session | SPDY session |
stream | stream to terminate |
status | code for the RST_STREAM frame |
Definition at line 1663 of file session.c.
References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, SPDYF_Response_Queue::data_size, HTON31, NULL, SPDYF_Response_Queue::process_response_handler, SPDY_CONTROL_FRAME_TYPES_RST_STREAM, SPDY_NO, SPDY_VERSION, SPDY_YES, SPDYF_handler_write_rst_stream(), SPDYF_queue_response(), SPDYF_Response_Queue::stream, and SPDYF_Stream::stream_id.
Referenced by spdyf_handler_read_syn_stream(), SPDYF_handler_write_data(), and SPDYF_session_idle().
int SPDYF_prepare_window_update | ( | struct SPDY_Session * | session, |
struct SPDYF_Stream * | stream, | ||
int32_t | delta_window_size | ||
) |
Prepares WINDOW_UPDATE frame to tell the other party that more data can be sent on the stream. The frame will be put at the head of the queue.
session | SPDY session |
stream | stream to which the changed window will apply |
delta_window_size | how much the window grows |
Definition at line 1719 of file session.c.
References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, SPDYF_Response_Queue::data_size, HTON31, NULL, SPDYF_Response_Queue::process_response_handler, SPDY_CONTROL_FRAME_TYPES_WINDOW_UPDATE, SPDY_NO, SPDY_VERSION, SPDY_YES, SPDYF_ASSERT, SPDYF_handler_write_window_update(), SPDYF_queue_response(), SPDYF_Response_Queue::stream, and SPDYF_Stream::stream_id.
Referenced by spdyf_handler_read_data().
void SPDYF_queue_response | ( | struct SPDYF_Response_Queue * | response_to_queue, |
struct SPDY_Session * | session, | ||
int | consider_priority | ||
) |
Puts SPDYF_Response_Queue object on the queue to be sent to the client later.
response_to_queue | linked list of objects containing SPDY frame and data to be added to the queue |
session | SPDY session for which the response is sent |
consider_priority | if SPDY_NO, the list will be added to the end of the queue. If SPDY_YES, the response will be added after the last previously added response with priority of the request grater or equal to that of the current one. If -1, the object will be put at the head of the queue. |
Definition at line 1492 of file session.c.
References SPDYF_Response_Queue::next, NULL, SPDYF_Response_Queue::prev, SPDYF_Stream::priority, SPDY_Session::response_queue_head, SPDY_Session::response_queue_tail, SPDY_NO, SPDY_YES, SPDYF_ASSERT, and SPDYF_Response_Queue::stream.
Referenced by SPDY_queue_response(), SPDYF_prepare_goaway(), SPDYF_prepare_rst_stream(), and SPDYF_prepare_window_update().
int SPDYF_session_accept | ( | struct SPDY_Daemon * | daemon | ) |
Called to accept new TCP connection and create SPDY session.
daemon | SPDY_Daemon whose listening socket is used. |
Definition at line 1387 of file session.c.
References SPDY_Session::addr, SPDY_Session::addr_len, SPDY_Daemon::cls, SPDY_Session::daemon, DLL_insert, SPDY_Session::fio_close_session, SPDY_Session::fio_new_session, SPDY_Daemon::io_subsystem, SPDY_Session::last_activity, SPDY_Session::max_num_frames, SPDY_Daemon::max_num_frames, SPDY_Daemon::new_session_cb, NULL, SPDY_Session::read_buffer, SPDY_Session::read_buffer_size, SPDY_Daemon::sessions_head, SPDY_Daemon::sessions_tail, SPDY_Session::socket_fd, SPDY_Daemon::socket_fd, SPDY_NO, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_YES, SPDYF_ASSERT, SPDYF_BUFFER_SIZE, SPDYF_io_set_session(), SPDYF_monotonic_time(), SPDYF_zlib_deflate_end(), SPDYF_zlib_deflate_init(), SPDYF_zlib_inflate_init(), SPDY_Session::status, SPDY_Session::zlib_recv_stream, and SPDY_Session::zlib_send_stream.
Referenced by SPDYF_run().
void SPDYF_session_close | ( | struct SPDY_Session * | session | ) |
This function shutdowns the socket, moves the session structure to daemon's queue for sessions to be cleaned up.
session | SPDY_Session which will be handled. |
Definition at line 1358 of file session.c.
References SPDY_Daemon::cleanup_head, SPDY_Daemon::cleanup_tail, SPDY_Daemon::cls, SPDY_Session::daemon, DLL_insert, DLL_remove, SPDY_Session::fio_close_session, NULL, SPDY_Session::read_closed, SPDY_Daemon::session_closed_cb, SPDY_Daemon::sessions_head, SPDY_Daemon::sessions_tail, SPDY_Session::socket_fd, SPDY_NO, and SPDY_YES.
Referenced by spdyf_close_all_sessions(), and SPDYF_session_idle().
void SPDYF_session_destroy | ( | struct SPDY_Session * | session | ) |
Cleans up the TSL context for the session, closes the TCP connection, cleans up any data pointed by members of the session structure (buffers, queue of responses, etc.) and frees the memory allocated by the session itself.
Definition at line 1573 of file session.c.
References SPDY_Session::addr, DLL_remove, SPDYF_Response_Queue::frqcb, SPDYF_Response_Queue::frqcb_cls, NULL, SPDY_Session::read_buffer, SPDY_Session::response_queue_head, SPDY_Session::response_queue_tail, SPDY_Session::socket_fd, SPDY_RESPONSE_RESULT_SESSION_CLOSED, SPDYF_response_queue_destroy(), SPDYF_stream_destroy(), SPDYF_zlib_deflate_end(), SPDYF_zlib_inflate_end(), SPDY_Session::streams_head, SPDY_Session::streams_tail, SPDY_Session::write_buffer, SPDY_Session::zlib_recv_stream, and SPDY_Session::zlib_send_stream.
Referenced by spdyf_cleanup_sessions().
int SPDYF_session_idle | ( | struct SPDY_Session * | session | ) |
Called by the daemon on SPDY_run to handle the data in the read and write buffer of a session. Based on the state and the content of the read buffer new frames are received and interpreted, appropriate user callbacks are called and maybe something is put on the response queue ready to be handled by session_write.
session | SPDY_Session which will be handled. |
Definition at line 1153 of file session.c.
References SPDY_Session::current_stream_id, SPDY_Session::daemon, SPDY_Session::frame_handler, SPDY_Session::frame_handler_cls, SPDY_Session::last_activity, NULL, SPDY_Session::read_buffer, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_Session::read_ignore_bytes, SPDY_Daemon::session_timeout, SPDY_CONTROL_FRAME_TYPES_GOAWAY, SPDY_CONTROL_FRAME_TYPES_RST_STREAM, SPDY_CONTROL_FRAME_TYPES_SYN_STREAM, SPDY_GOAWAY_STATUS_OK, SPDY_GOAWAY_STATUS_PROTOCOL_ERROR, SPDY_NO, SPDY_RST_STREAM_STATUS_FRAME_TOO_LARGE, SPDY_SESSION_STATUS_CLOSING, SPDY_SESSION_STATUS_FLUSHING, SPDY_SESSION_STATUS_IGNORE_BYTES, SPDY_SESSION_STATUS_WAIT_FOR_BODY, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER, SPDY_VERSION, SPDY_YES, SPDYF_ASSERT, SPDYF_CONTROL_FRAME_NTOH, SPDYF_DATA_FRAME_NTOH, SPDYF_DEBUG, SPDYF_handler_ignore_frame(), spdyf_handler_read_data(), spdyf_handler_read_goaway(), spdyf_handler_read_rst_stream(), spdyf_handler_read_syn_stream(), SPDYF_monotonic_time(), SPDYF_prepare_goaway(), SPDYF_prepare_rst_stream(), SPDYF_session_close(), SPDYF_session_write(), SPDY_Session::status, and SPDY_Session::streams_head.
Referenced by SPDYF_run().
int SPDYF_session_read | ( | struct SPDY_Session * | session | ) |
Called by the daemon when the socket for the session has available data to be read. Reads data from the TLS socket and puts it to the session's read buffer. The latte
session | SPDY_Session for which data will be read. |
Definition at line 864 of file session.c.
References SPDY_Session::fio_recv, SPDY_Session::frame_handler, SPDY_Session::frame_handler_cls, SPDY_Session::last_activity, NULL, SPDY_Session::read_buffer, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_Session::read_buffer_size, SPDY_Session::read_closed, SPDY_Session::socket_fd, SPDY_GOAWAY_STATUS_INTERNAL_ERROR, SPDY_IO_ERROR_AGAIN, SPDY_IO_ERROR_CLOSED, SPDY_IO_ERROR_ERROR, SPDY_NO, SPDY_SESSION_STATUS_CLOSING, SPDY_SESSION_STATUS_FLUSHING, SPDY_SESSION_STATUS_IGNORE_BYTES, SPDY_SESSION_STATUS_WAIT_FOR_BODY, SPDY_SESSION_STATUS_WAIT_FOR_HEADER, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER, SPDY_YES, SPDYF_ASSERT, spdyf_handler_read_data(), SPDYF_monotonic_time(), SPDYF_prepare_goaway(), and SPDY_Session::status.
Referenced by SPDYF_run().
int SPDYF_session_write | ( | struct SPDY_Session * | session, |
bool | only_one_frame | ||
) |
Called by the daemon when the socket for the session is ready for some data to be written to it. For one or more objects on the response queue tries to fill in the write buffer, based on the frame on the queue, and to write data to the TLS socket.
session | SPDY_Session for which data will be written. |
only_one_frame | when true, the function will write at most one SPDY frame to the underlying IO subsystem; when false, the function will write up to session->max_num_frames SPDY frames |
Definition at line 979 of file session.c.
References SPDYF_Response_Queue::control_frame, DLL_remove, SPDY_Session::fio_after_write, SPDY_Session::fio_before_write, SPDY_Session::fio_send, SPDYF_Response_Queue::frqcb, SPDYF_Response_Queue::frqcb_cls, SPDYF_Response_Queue::is_data, SPDYF_Stream::is_out_closed, SPDY_Session::last_activity, SPDY_Session::max_num_frames, SPDYF_Response_Queue::next, NULL, SPDYF_Response_Queue::prev, SPDYF_Response_Queue::process_response_handler, SPDY_Session::read_closed, SPDY_Session::response_queue_head, SPDY_Session::response_queue_tail, SPDY_Session::socket_fd, SPDY_CONTROL_FRAME_TYPES_GOAWAY, SPDY_GOAWAY_STATUS_INTERNAL_ERROR, SPDY_IO_ERROR_AGAIN, SPDY_IO_ERROR_CLOSED, SPDY_IO_ERROR_ERROR, SPDY_NO, SPDY_RESPONSE_RESULT_STREAM_CLOSED, SPDY_RESPONSE_RESULT_SUCCESS, SPDY_SESSION_STATUS_CLOSING, SPDY_SESSION_STATUS_FLUSHING, SPDY_YES, SPDYF_monotonic_time(), SPDYF_prepare_goaway(), SPDYF_response_queue_destroy(), SPDYF_session_write(), SPDYF_stream_set_flags_on_write(), SPDY_Session::status, SPDYF_Response_Queue::stream, SPDY_Session::write_buffer, SPDY_Session::write_buffer_beginning, SPDY_Session::write_buffer_offset, and SPDY_Session::write_buffer_size.
Referenced by spdyf_close_all_sessions(), SPDYF_run(), SPDYF_session_idle(), and SPDYF_session_write().