mi::http::IConnection Class Reference
[HTTP server]
Description
The connection class represents a connection from a client to the server. An instance of this interface is passed into the various registered callbacks.
-
A pointer to an mi::http::IConnection interface is only valid inside mi::http::IRequest_handler::handle(), mi::http::ICGIRequest_handler::handle(), mi::http::IResponse_handler::handle(), or mi::http::IData_handler::handle().
-
This interface is not derived from mi::base::IInterface. As one consequence, there are no retain() and release() methods, and the interface cannot be used together with the mi::base::Handle class.
Public Member Functions
- virtual void add_data_handler( IData_handler* handler) =0
- Adds a data handler to the connection. More...
- virtual bool check_error() =0
- Indicates whether an error occurred on the connection. More...
- virtual bool enqueue( neuraylib::IBuffer* buffer) =0
- Enqueues a buffer to be sent on the connection. More...
- virtual Sint32 flush() =0
- Waits until all enqueued data has been written. More...
- virtual const char* get_attachment( const char* key) =0
- Returns a string attachment from the connection. More...
- virtual IData* get_data_attachment( const char* key) =0
- Returns an attachment from the connection. More...
- template< class T>T* get_data_attachment( const char* key)
- Returns an attachment from the connection. More...
- virtual const char* get_local_address() =0
- Returns the address of the local side of the connection.
- virtual const char* get_peer_address() =0
- Returns the address of the peer of the connection.
- virtual IRequest* get_request() =0
- Returns the request of the connection.
- virtual IResponse* get_response() =0
- Returns the response associated with the connection.
- virtual bool print( const char* string) =0
- Prints a string to the connection. More...
- bool printf( const char* string, ...)
- Prints a string to the connection. More...
- virtual Sint32 read_data( Size size, char* buffer) =0
- Reads incoming CGI data into a supplied buffer. More...
- virtual void remove_attachment( const char* key) =0
- Removes an attachment from the connection. More...
- virtual void set_attachment( const char* key, const char* value) =0
- Attaches a string attachment to the connection. More...
- virtual void set_data_attachment( const char* key, IData* value) =0
- Attaches an attachment to the connection. More...
Member Functions
- virtual void mi::http::IConnection::add_data_handler( IData_handler* handler) [pure virtual]
-
Adds a data handler to the connection. The handler is removed when the connection is closed or when the handler's handle() method returns NULL.
Parameters
- handler
- The data handler.
- virtual bool mi::http::IConnection::check_error() [pure virtual]
-
Indicates whether an error occurred on the connection.
Returns
true , if there was an error, false otherwise.
- virtual bool mi::http::IConnection::enqueue( neuraylib::IBuffer* buffer) [pure virtual]
-
Enqueues a buffer to be sent on the connection.
Note:The buffer might be modified or discarded by data handlers before being sent. The string might be queued before it is actually sent. See also flush().
Parameters
- buffer
- The buffer to be written. Ownership of the buffer passes from the caller to the connection.
Returns
true , in case of success, and false in case of failure.
- virtual Sint32 mi::http::IConnection::flush() [pure virtual]
-
Waits until all enqueued data has been written.
Returns
0, in case of success, and -1 in case of failure.
- virtual const char* mi::http::IConnection::get_attachment( const char* key) [pure virtual]
-
Returns a string attachment from the connection. Attachments can be used for communication between different handlers. This convenience methods deals with string attachments. Use get_data_attachment() for all other data types.
Parameters
- key
- The key of the attachment.
Returns
The value of the attachment, or NULL if there is no such attachment.
- virtual IData* mi::http::IConnection::get_data_attachment( const char* key) [pure virtual]
-
Returns an attachment from the connection. Attachments can be used for communication between different handlers. This methods deals with arbitrary attachment types. The method get_attachment() is more convenient for string attachments.
Parameters
- key
- The key of the attachment.
Returns
The value of the attachment, or NULL if there is no such attachment.
-
template< class T>
T* mi::http::IConnection::get_data_attachment( const char* key) [inline] -
Returns an attachment from the connection. Attachments can be used for communication between different handlers. This methods deals with arbitrary attachment types. The method get_attachment() is more convenient for string attachments.
This templated member function is a wrapper of the non-template variant for the user's convenience. It eliminates the need to call mi::base::IInterface::get_interface( const Uuid &) on the returned pointer, since the return type already is a pointer to the type T specified as template parameter.
Parameters
- key
- The key of the attachment.
Returns
The value of the attachment, or NULL if there is no such attachment.
- virtual const char* mi::http::IConnection::get_local_address() [pure virtual]
-
Returns the address of the local side of the connection.
- virtual const char* mi::http::IConnection::get_peer_address() [pure virtual]
-
Returns the address of the peer of the connection.
- virtual IRequest* mi::http::IConnection::get_request() [pure virtual]
-
Returns the request of the connection.
- virtual IResponse* mi::http::IConnection::get_response() [pure virtual]
-
Returns the response associated with the connection.
- virtual bool mi::http::IConnection::print( const char* string) [pure virtual]
-
Prints a string to the connection.
Note:The string might be modified or discarded by data handlers before being sent. The string might be queued before it is actually sent. See also flush().
Parameters
- string
- The string to be written.
Returns
true , in case of success, and false in case of failure.
- bool mi::http::IConnection::printf( const char* string, ...)
-
Prints a string to the connection.
Note:The string might be modified or discarded by data handlers before being sent. The string might be queued before it is actually sent. See also flush().
Parameters
- string
- The string to be written using printf()-like format specifiers, followed by matching arguments. The formatted message is limited to 1024 characters.
Returns
true , in case of success, and false in case of failure.
- virtual Sint32 mi::http::IConnection::read_data( Size size, char* buffer) [pure virtual]
-
Reads incoming CGI data into a supplied buffer. This method can only be called by CGI handlers. The total amount of data is limited by the advised Content-Length header.
Note:This method blocks until the given amount of bytes have been read, until the content length is exhausted, or the connection was closed.
Parameters
- size
- The size of the buffer.
- buffer
- The buffer to write the the data into.
Returns
The number of bytes read or 0 if no more data will come.
- virtual void mi::http::IConnection::remove_attachment( const char* key) [pure virtual]
-
Removes an attachment from the connection. Attachments can be used for communication between different handlers.
Parameters
- key
- The key of the attachment.
- virtual void mi::http::IConnection::set_attachment( const char* key, const char* value) [pure virtual]
-
Attaches a string attachment to the connection. Attachments can be used for communication between different handlers. This convenience methods deals with string attachments. Use set_data_attachment() for all other data types.
Parameters
- key
- Key of the attachment.
- value
- Value of the attachment.
- virtual void mi::http::IConnection::set_data_attachment( const char* key, IData* value) [pure virtual]
-
Attaches an attachment to the connection. Attachments can be used for communication between different handlers. This methods deals with arbitrary attachment types. The method set_attachment() is more convenient for string attachments.
Parameters
- key
- Key of the attachment.
- value
- Value of the attachment.