DiCE API nvidia_logo_transpbg.gif Up
mi::http::IConnection Class Referenceabstract

The connection class represents a connection from a client to the server. More...

#include <http.h>

Public Member Functions

virtual const char * get_peer_address ()=0
 Returns the address of the peer of the connection. More...
 
virtual const char * get_local_address ()=0
 Returns the address of the local side of the connection. More...
 
virtual bool print (const char *string)=0
 Prints a string to the connection. More...
 
bool printf (const char *string,...) __attribute__((format(printf
 Prints a string to 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 bool check_error ()=0
 Indicates whether an error occurred on the connection. More...
 
virtual IRequestget_request ()=0
 Returns the request of the connection. More...
 
virtual IResponseget_response ()=0
 Returns the response associated with the connection. More...
 
virtual void add_data_handler (IData_handler *handler)=0
 Adds a data handler to the connection. More...
 
virtual void set_data_attachment (const char *key, IData *value)=0
 Attaches an attachment to the connection. More...
 
virtual IDataget_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 void set_attachment (const char *key, const char *value)=0
 Attaches a string attachment to the connection. More...
 
virtual const char * get_attachment (const char *key)=0
 Returns a string attachment from the connection. More...
 
virtual void remove_attachment (const char *key)=0
 Removes an attachment from the connection. More...
 
virtual Sint32 read_data (Size size, char *buffer)=0
 Reads incoming CGI data into a supplied buffer. More...
 
virtual bool is_secure_connection ()=0
 Query whether this is a secure (i.e. More...
 

Detailed 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.

Note
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.

Member Function Documentation

 add_data_handler()

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
handlerThe data handler.

 check_error()

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.

 enqueue()

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
bufferThe 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.

 flush()

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.

 get_attachment()

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
keyThe key of the attachment.
Returns
The value of the attachment, or NULL if there is no such attachment.

 get_data_attachment() [1/2]

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.

Template Parameters
TThe interface type of the requested element.
Parameters
keyThe key of the attachment.
Returns
The value of the attachment, or NULL if there is no such attachment.

 get_data_attachment() [2/2]

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
keyThe key of the attachment.
Returns
The value of the attachment, or NULL if there is no such attachment.

 get_local_address()

virtual const char * mi::http::IConnection::get_local_address ( )
pure virtual

Returns the address of the local side of the connection.

 get_peer_address()

virtual const char * mi::http::IConnection::get_peer_address ( )
pure virtual

Returns the address of the peer of the connection.

 get_request()

virtual IRequest * mi::http::IConnection::get_request ( )
pure virtual

Returns the request of the connection.

 get_response()

virtual IResponse * mi::http::IConnection::get_response ( )
pure virtual

Returns the response associated with the connection.

 is_secure_connection()

virtual bool mi::http::IConnection::is_secure_connection ( )
pure virtual

Query whether this is a secure (i.e.

HTTPS) connection

Returns
A bool indicating whether this is a secure connection

 print()

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
stringThe string to be written.
Returns
true, in case of success, and false in case of failure.

 printf()

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
stringThe string to be written using printf()-like format specifiers, followed by matching arguments. The formatted message is limited to 16383 characters.
Returns
true, in case of success, and false in case of failure.

 read_data()

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
sizeThe size of the buffer.
bufferThe buffer to write the the data into.
Returns
The number of bytes read or 0 if no more data will come.

 remove_attachment()

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
keyThe key of the attachment.

 set_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
keyKey of the attachment.
valueValue of the attachment.

 set_data_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
keyKey of the attachment.
valueValue of the attachment.