The Fast Light Environment Kit



class FSocket

Include Files

#include <Flek/FSocket.H>

Description

FSocket is an abstract socket interface. FSocket was adapted from K.A. Knizhnik's very nice SAL library. It provides a socket implementation based on the socket library provided by the operating system. As local sockets are not supported under Win32, shared memory and semaphore objects are used to provide high speed communications on the same computer.

Methods


Method Descriptions

accept

virtual FSocket* FSocket::accept();

Accept new socket. This method is called by server to establish a connection with the new client. When the client executes a connect method to the access server's accept port, accept method will create new socket, which can be used for communication with the client. The accept method will block the current task until some connection is established.

Return Value
Pointer to new socket or NULL if operation failed.

cancel_accept

virtual int FSocket::cancel_accept();

Cancel accept operation. Task blocked in accept call is woken and execution continues.

Return Value
1 if socket was successfully closed, 0 otherwise.

close

virtual int FSocket::close();

Close socket connection.

Return Value
1 if operation successfully completed, 0 otherwise.

connect

static FSocket* FSocket::connect(char const* address, socket_domain domain = sock_any_domain, int max_attempts = DEFAULT_CONNECT_MAX_ATTEMPTS, time_t timeout = DEFAULT_RECONNECT_TIMEOUT);

Establish connection with server. This method will do at most max_attempts attempts to connect server, with timeout interval between attempts.

Parameters
addressAddress of server socket in format "hostname:port".
domainType of connection. The following values of this parameter are recognized:
  • sock_any_domain = domain is chosen automatically.
  • sock_local_domain = local domain (connection with one host).
  • sock_global_domain = internet domain.
If sock_any_domain is specified, local connection is chosen when either port was omitted in specification of the address or hostname is "localhost", and global connection is used in all other cases.
max_attemptsMaximal number of attempts to connect to server.
timeoutTimeout in seconds between attempts to connect the server.

Return Value
This method always create new socket object and returns a pointer to it. If connection with server was not established, this socket contains error code describing reason of failure. So returned socket should be first checked by the valid() method.

create_global

static FSocket* FSocket::create_global(char const* address, int listen_queue_size = DEFAULT_LISTEN_QUEUE_SIZE);

Create and open socket in global (internet) domain at the server site.

Parameters
addressAddress to be assigned to the socket.
listen_queue_sizeSize of listen queue.

Return Value
This method always create new socket object and returns pointer to it. If socket can not be opened, error code field of returned socket describes the reason of failure. So returned socket should be first checked by the valid() method.

create_local

static FSocket* FSocket::create_local(char const* address, int listen_queue_size = DEFAULT_LISTEN_QUEUE_SIZE);

Create and open socket in local domain at the server site.

Parameters
addressAddress to be assigned to the socket.
listen_queue_sizeSize of listen queue.

Return Value
This method always create new socket object and returns pointer to it. If socket can not be opened, error code field of returned socket describes the reason of failure. So returned socket should be first checked by the valid() method.

get_error_text

virtual void FSocket::get_error_text(char* buf, size_t buf_size);

Get error message text for the last operation.

Parameters
bufBuffer to receive text of the error message.
buf_sizeSize of buffer, no more than buf_size bytes will be placed in the buffer.

read

virtual int FSocket::read(void* buf, size_t size);

Read data from socket.

Parameters
bufBuffer to hold fetched data.
buf_sizeNumber of bytes to fetch.

Return Value
1 if operation successfully completed, 0 otherwise.

shutdown

virtual int FSocket::shutdown();

Shutdown the socket. This function prohibits write and read operation on the socket. All further attempts to read or write data from/to the socket will be denied. But all previously initiated operations are guaranteed to be completed.

Return Value
1 if operation successfully completed, 0 otherwise.

valid

virtual int FSocket::valid();

Check the status of the last operation with socket.

Return Value
1 if the last operation completed successfully, 0 otherwise.

write

virtual int FSocket::write(void const* buf, size_t size);

Write data to socket.

Parameters
bufBuffer that contains the data to be sent.
buf_sizeNumber of bytes to send.

Return Value
1 if operation successfully completed, 0 otherwise.


© 2000 the Flek Development team.
Generated by ScanDoc
Last Updated: Tue May 15 8:50:06 2001