Socket_IO


Derived from: BDataIO

Declared in: TCP_IO.h

Library: libHTTP.so


Overview


The Socket_IO class provides a BDataIO based wrapper for the BSD sockets interface. See the Network Kit documentation for information on the BSD sockets interface.

See TCP_IO and TCP_Listener for use with TCP.


Constructor and Destructor


Socket_IO()


	Socket_IO( int socket )

Create a new Socket_Io and wrap the socket specified by socket.


~Socket_IO()


	virtual ~Socket_IO( void )

Delete this object. If close-on-delete is enabled, the socket passed to the constructor is closed. close-on-delete is false by default.


Member Functions


Read()


	virtual ssize_t Read( void *buffer, size_t numBytes )

Read from the socket.


Write()


	virtual ssize_t Write( const void *buffer, size_t numBytes )

Write to the socket.


Connect()


	status_t Connect( const char *IPname, unsigned short port )
	int Connect( const struct sockaddr_in *remote_interface )

Connect to the host specified by IPname on port. IPname can be either a host name or an IP address.

The second format is more of the conventinal BSD sockets flavor.


Bind()


	int Bind( unsigned short port, int32 address = INADDR_ANY )

Bind to port on the interface specified by address. The defualt argument of address, INADDR_ANY, tells Bind() to bind to all interfaces. Despite what it says in the BeBook, INADDR_ANY appears to work.


Listen()


	int Listen( int acceptance_count )

Listen() enables the socket to receive connections. The acceptance_count is the length of the acceptance queue. This is the maximum number of requests which can be waiting to be accepted. When the acceptance queue is full, further attempts to connect will fail. It is not the maximum number of simultaneous connections which can be handled. As soon a Accept() is called, a space is freed in the queue. This number need not be very high if accepted connections are passed to their own thread and the listener returns to calling Accept() immediately.


Accept()


	int Accept( struct sockaddr *client_interface, int *client_size )

If blocking is enabled for this socket, Accept blocks until a client attempts to connect. It then returns a new socket token for the accepted connection and can go back to accepting connections. client_interface returns information on the remote client.


Close()


	int Close( void )

Close the connection.


SetCOD()


	void SetCOD( bool flag )

This controls the close-on-delete function. If set to true, the socket will be closed when the object is deleted. By default it is set to false.


SetBlocking()


	void SetBlocking( bool shouldBlock )

Setting this to true will cause io to block. Setting it to false will set io to non-blocking mode. Io blocks by default.


GetSocket()


int GetSocket( void )

Returns the socket token used by this object.


GetPeerName()


	const char *GetPeerName( void )

Returns the IP name of the remote interface.


libHTTP - A high-level HTTP API for the BeOS


Copyright (C) 1999 Joe Kloss