GNU libmicrohttpd  0.9.29
session.h File Reference

TCP connection/SPDY session handling. More...

#include "platform.h"
#include "structures.h"
Include dependency graph for session.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int SPDYF_session_read (struct SPDY_Session *session)
 
int SPDYF_session_write (struct SPDY_Session *session, bool only_one_frame)
 
int SPDYF_session_idle (struct SPDY_Session *session)
 
void SPDYF_session_close (struct SPDY_Session *session)
 
int SPDYF_session_accept (struct SPDY_Daemon *daemon)
 
void SPDYF_queue_response (struct SPDYF_Response_Queue *response_to_queue, struct SPDY_Session *session, int consider_priority)
 
void SPDYF_session_destroy (struct SPDY_Session *session)
 
int SPDYF_prepare_goaway (struct SPDY_Session *session, enum SPDY_GOAWAY_STATUS status, bool in_front)
 
int SPDYF_prepare_rst_stream (struct SPDY_Session *session, struct SPDYF_Stream *stream, enum SPDY_RST_STREAM_STATUS status)
 
int SPDYF_prepare_window_update (struct SPDY_Session *session, struct SPDYF_Stream *stream, int32_t delta_window_size)
 
int SPDYF_handler_write_data (struct SPDY_Session *session)
 
int SPDYF_handler_write_syn_reply (struct SPDY_Session *session)
 
int SPDYF_handler_write_goaway (struct SPDY_Session *session)
 
int SPDYF_handler_write_rst_stream (struct SPDY_Session *session)
 
int SPDYF_handler_write_window_update (struct SPDY_Session *session)
 
void SPDYF_handler_ignore_frame (struct SPDY_Session *session)
 

Detailed Description

TCP connection/SPDY session handling.

Author
Andrey Uzunov

Definition in file session.h.

Function Documentation

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.

Parameters
sessionSPDY_Session whose read buffer is used.

Definition at line 830 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().

Here is the caller graph for this function:

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.

Returns
SPDY_NO on error (not enough memory or the user calback for providing response data did something wrong). If the error is unrecoverable the handler changes session's status. SPDY_YES on success

Definition at line 570 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
sessionSPDY session
Returns
SPDY_NO on error (not enough memory; by specification the session must be closed soon, thus there is no need to handle the error) or SPDY_YES on success

Definition at line 517 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().

Here is the caller graph for this function:

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.

Parameters
sessionSPDY session
Returns
SPDY_NO on error (not enough memory). If the error is unrecoverable the handler changes session's status. SPDY_YES on success

Definition at line 742 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().

Here is the caller graph for this function:

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.

Parameters
sessionSPDY session
Returns
SPDY_NO on error (zlib state is broken; the session MUST be closed). If the error is unrecoverable the handler changes session's status. SPDY_YES on success

Definition at line 422 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
sessionSPDY session
Returns
SPDY_NO on error (not enough memory). If the error is unrecoverable the handler changes session's status. SPDY_YES on success

Definition at line 787 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().

Here is the caller graph for this function:

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.

Parameters
sessionSPDY session
statuscode for the GOAWAY frame
in_frontwhether or not to put the frame in front of everything on the response queue
Returns
SPDY_NO on error (not enough memory) or SPDY_YES on success

Definition at line 1617 of file session.c.

References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
sessionSPDY session
streamstream to terminate
statuscode for the RST_STREAM frame
Returns
SPDY_NO on memory error or SPDY_YES on success

Definition at line 1665 of file session.c.

References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
sessionSPDY session
streamstream to which the changed window will apply
delta_window_sizehow much the window grows
Returns
SPDY_NO on memory error or SPDY_YES on success

Definition at line 1721 of file session.c.

References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
response_to_queuelinked list of objects containing SPDY frame and data to be added to the queue
sessionSPDY session for which the response is sent
consider_priorityif 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 1494 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().

Here is the caller graph for this function:

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.

Parameters
sessionSPDY_Session which will be handled.

Definition at line 1360 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().

Here is the caller graph for this function:

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 1575 of file session.c.

References SPDY_Session::addr, DLL_remove, SPDYF_Response_Queue::frqcb, SPDYF_Response_Queue::frqcb_cls, MHD_socket_close_, 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
sessionSPDY_Session which will be handled.
Returns
SPDY_YES if something from the read buffers was processed, session's status was changed and/or the session was closed. SPDY_NO if nothing happened, e.g. the session is in a state, not allowing processing read buffers.

Definition at line 1155 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Parameters
sessionSPDY_Session for which data will be read.
Returns
SPDY_YES if something was read or session's status was changed. It is possible that error occurred but was handled and the status was therefore changed. SPDY_NO if nothing happened, e.g. the subsystem wants read/ write to be called again.

Definition at line 866 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
sessionSPDY_Session for which data will be written.
only_one_framewhen 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
Returns
SPDY_YES if the session's internal writing state has changed: something was written and/or session's status was changed and/or response callback was called but did not provide data. It is possible that error occurred but was handled and the status was therefore changed. SPDY_NO if nothing happened. However, it is possible that some frames were discarded within the call, e.g. frames belonging to a closed stream.

Definition at line 981 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().

Here is the call graph for this function:

Here is the caller graph for this function: