Socket Class Reference

[APE Index] [APE Hierarchy] [Headers]


The Socket is used as the base for all Internet protocol services under APE More...

#include <socket.h>

Public Members

Protected Members


Detailed Description

The Socket is used as the base for all Internet protocol services under APE. A socket is a system resource (or winsock descriptor) that occupies a specific port address (and may be bound to a specific network interface) on the local machine. The socket may also be directly connected to a specific socket on a remote internet host.


Socket(int domain, int type, int protocol = 0) [public]

An unconnected socket may be created directly on the local machine. Sockets can occupy both the internet domain (AF_INET) and UNIX socket domain (AF_UNIX) under unix. The socket type (SOCK_STREAM, SOCK_DGRAM) and protocol may also be specified. If the socket cannot be created, an exception is thrown.

Parameters:
domain socket domain to use.
protocol specific protocol to apply.
type base type and protocol family of the socket.

Socket(int fd) [public]

A socket object may be created from a file descriptor when that descriptor was created either through a socket() or accept() call. This constructor is mostly for internal use.

Parameters:
fd file descriptor of an already existing socket.

Socket(const Socket &source) [public]

A socket can also be constructed from an already existing Socket object. The socket file descriptor is dup()'d. This does not exist under win32.

Parameters:
source of existing socket to clone.

Socket& operator=(const Socket &from) [public]

Sockets may also be duplicated by the assignment operator.

void setCompletion(int mode) [public]

Used to specify blocking mode for the socket. A socket can be made non-blocking by setting SOCKET_COMPLETION_DELAYED or set to block on all access with SOCKET_COMPLETION_IMMEDIATE. I do not believe this form of non-blocking socket I/O is supported in winsock, though it provides an alternate asynchronous set of socket services.

Parameters:
mode specify socket I/O call blocking mode.

inlineint Read(void *addr, size_t len) [public virtual]

Read an arbitrary byte data stream from the socket. This is made a virtual function so that derived classes can implement special data encoding for specific protocols such as in-stream MIME decoding, or to create timed streaming services.

Parameters:
addr pointer to store read data.
len number of bytes to read.
Returns:
number of bytes read on success, -1 on error.

inlineint Write(void *addr, size_t len) [public virtual]

Write an arbitrary byte data stream from the socket. This is made a virtual function so that derived classes can implement special data encoding for specific protocols such as in-stream MIME encoding, or to create timed streaming services.

Parameters:
addr pointer to write data from.
len number of bytes to write.
Returns:
number of bytes written on success, -1 on error.

inlineint Write(char *msg) [public virtual]

Write a null terminated string directly to a socket. This is made a virtual function so that derived classes can implement special data encoding for specific protocols such as in-stream MIME encoding, or to create timed streaming services.

Parameters:
msg null terminated ASCII string to write.
Returns:
number of bytes written on success, -1 on failure.

inlineint Peek(void *addr, size_t len) [public virtual]

This allows one to peek at data waiting at the "head stream" of the socket. Peeking allows protocols to determine both if data is available, and, for some protocols, what kind of data to expect, to make processing more efficient.

Parameters:
addr to read socket head queue into.
len number of bytes to try and read from the socket.
Returns:
number of bytes available.

InetHostAddress Peek(short *port = NULL) [public]

This specific Peek method can be used to return the internet host address of the sender of the next packet to be read. For TCP servers, the Peek method can be used to determine the address of the next socket connection request and thereby determine if it should be accepted or not.

Parameters:
port pointer to store port address of sending socket.
Returns:
address of sending host.

Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
Kdoc