|
Zen API
|
Represents a network socket.
Inheritance diagram for kSocket:Public Member Functions | |
| kAlloc | kObject_Alloc (kObject object) |
| Gets the memory allocator associated with this object. More... | |
| kStatus | kObject_Clone (kObject *object, kObject source, kAlloc allocator) |
| Constructs a new object by copying an existing object, including any aggregated child elements. More... | |
| kStatus | kObject_Destroy (kObject object) |
| Destroys the object. More... | |
| kStatus | kObject_Dispose (kObject object) |
| Destroys the object and any aggregated child elements. More... | |
| kBool | kObject_Equals (kObject object, kObject other) |
| Determines whether the object is equal to another object. More... | |
| kSize | kObject_HashCode (kObject object) |
| Gets a hash code representing the state of this object. More... | |
| kBool | kObject_Is (kObject object, kType type) |
| Determines whether this object is an instance of the specified type. More... | |
| kBool | kObject_IsShared (kObject object) |
| Reports whether the object is currently shared (reference count greater than one). More... | |
| kStatus | kObject_SetPool (kObject object, kObjectPool pool) |
| Sets the object pool associated with this object. More... | |
| kStatus | kObject_Share (kObject object) |
| Increments the reference count associated with this object. More... | |
| kSize | kObject_Size (kObject object) |
| Estimates the memory consumed by this object, including any aggregated child elements. More... | |
| kType | kObject_Type (kObject object) |
| Returns the type of the object. More... | |
| kStatus | kSocket_Accept (kSocket socket, kSocket *connection, kAlloc allocator) |
| Blocks until an incoming connection request is accepted. More... | |
| kStatus | kSocket_Bind (kSocket socket, kIpAddress address, k32u port) |
| Binds the socket to a local IP address and/or port. More... | |
| kStatus | kSocket_BindToDevice (kSocket socket, const kChar *interfaceName) |
| Binds the socket to a specific network interface. More... | |
| kStatus | kSocket_Connect (kSocket socket, kIpAddress address, k32u port, k64u timeout) |
| Connects the socket to a remote end point. More... | |
| kStatus | kSocket_Construct (kSocket *socket, kIpVersion ipVersion, kSocketType socketType, kAlloc allocator) |
| Constructs a kSocket object. More... | |
| kStatus | kSocket_EnableBroadcast (kSocket socket, kBool broadcast) |
| Enables or disables datagram broadcasting. More... | |
| kStatus | kSocket_EnableReuseAddress (kSocket socket, kBool reuse) |
| Enables or disables reuse of a local end point within a short period of time. More... | |
| kSocketEvent | kSocket_Events (kSocket socket) |
| Gets the events detected during the most recent wait operation. More... | |
| kStatus | kSocket_Listen (kSocket socket, kSize backlog) |
| Places the socket into a listening state, to monitor for incoming connection requests. More... | |
| kStatus | kSocket_LocalEndPoint (kSocket socket, kIpEndPoint *endPoint) |
| Returns the local end point for a bound socket. More... | |
| kStatus | kSocket_Read (kSocket socket, void *buffer, kSize size, kSize *read) |
| Reads one or more bytes. More... | |
| kStatus | kSocket_ReadFrom (kSocket socket, kIpEndPoint *endPoint, void *buffer, kSize size, kSize *read) |
| Reads a datagram. More... | |
| kStatus | kSocket_RemoteEndPoint (kSocket socket, kIpEndPoint *endPoint) |
| Returns the remote end point for a connected socket. More... | |
| kStatus | kSocket_SetBlocking (kSocket socket, kBool isBlocking) |
| Determines whether the socket will block on read/write requests. More... | |
| kStatus | kSocket_SetEvents (kSocket socket, kSocketEvent events) |
| Sets the event types that a socket will wait on. More... | |
| kStatus | kSocket_SetLingerTime (kSocket socket, k64u lingerTime) |
| Specifies the duration that a TCP connection can remain open when the socket is closed in order to ensure that all outbound bytes are transmitted to the receiver. More... | |
| kStatus | kSocket_SetNoDelay (kSocket socket, kBool noDelay) |
| Can be used to disable the Nagle algorithm. More... | |
| kStatus | kSocket_SetReadBuffer (kSocket socket, kSize size) |
| Sets the size of the read buffer used by the underlying operating system. More... | |
| kStatus | kSocket_SetReadTimeout (kSocket socket, k64u timeout) |
| Sets the timeout duration for blocking read operations. More... | |
| kStatus | kSocket_SetWriteBuffer (kSocket socket, kSize size) |
| Sets the size of the write buffer used by the underlying operating system. More... | |
| kStatus | kSocket_SetWriteTimeout (kSocket socket, k64u timeout) |
| Sets the timeout duration for blocking write operations. More... | |
| kStatus | kSocket_Status (kSocket socket) |
| Reports any internal errors that will prevent success of future communication attempts. More... | |
| kStatus | kSocket_Wait (kSocket socket, k64u timeout) |
| Waits for a socket event. More... | |
| kStatus | kSocket_WaitAny (const kSocket *sockets, kSize count, k64u timeout) |
| Waits until an event occurs on one or more sockets. More... | |
| kStatus | kSocket_Write (kSocket socket, const void *buffer, kSize size, kSize *written) |
| Writes one or more bytes. More... | |
| kStatus | kSocket_WriteTo (kSocket socket, kIpAddress address, k32u port, const void *buffer, kSize size) |
| Sends a datagram. More... | |
Gets the memory allocator associated with this object.
Most objects are constructed with an allocator, which is used to allocate the memory required by the object. Objects retain a reference to this allocator to enable further allocations and to free memory when the object is destroyed.
| object | Object. |
Constructs a new object by copying an existing object, including any aggregated child elements.
If the source object is an object collection (e.g. kArrayList<kString>), any aggregated child objects are also cloned. In this case, the kObject_Dispose method can be used to free the cloned collection and its associated elements.
This method will fail if the source object (or an aggregated child element) does not support cloning.
| object | Receives the constructed object. |
| source | Source object. |
| allocator | Memory allocator (or kNULL for default). |
Destroys the object.
The kObject_Destroy method destroys the object itself and any resources that are owned by the object. See Object Destruction for more information.
When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.
| object | Object (or kNULL). |
Destroys the object and any aggregated child elements.
The kObject_Dispose method destroys the object itself, any resources that are owned by the object, and if the object represents a collection of objects, any child objects in the collection. See Object Destruction for more information.
When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.
| object | Object (or kNULL). |
Determines whether the object is equal to another object.
By default, objects are compared by reference; objects are considered equal if the given handles refer to the same object instance. However, some classes override the Equals method to provide a more meaningful comparison (e.g. kString).
| object | Object. |
| other | Object for comparison. |
Gets a hash code representing the state of this object.
By default, objects return a hash code based on the object handle value. However, some classes override the HashCode method to provide a more useful hash (e.g. kString).
| object | Object. |
Determines whether this object is an instance of the specified type.
This function compares the type of this object with the given type. An object is considered to be an instance of a given type if a) the type represents a class and this object inherits from (or instantiates) that class, or b) the type represents an interface and this object implements the interface.
| object | Object. |
| type | Type. |
Reports whether the object is currently shared (reference count greater than one).
Objects are initialized with a reference count of one. The kObject_Share method can be used to increment the reference count. The kObject_Destroy and kObject_Dispose methods decrease the reference count, and when the reference count reaches zero, the object is actually destroyed/disposed.
This method can be used to determine if the reference count of an object is currently greater than one.
This method is thread-safe.
| object | Object. |
|
inherited |
Sets the object pool associated with this object.
Object pools can be used to implement custom lifecycle management. If an object has an assigned pool, then the kObjectPool_Reclaim method will be called just prior to destruction, to provide an opportunity for the object to be reclaimed.
| object | Object. |
| pool | Pool object (or kNULL to clear the pool assignment). |
Increments the reference count associated with this object.
This method is thread-safe.
| object | Object. |
Estimates the memory consumed by this object, including any aggregated child elements.
This method can be optionally overridden by kObject-derived classes to report the amount of memory consumed by an object. The default implementation reports only the size of the class instance (additional allocations performed by the class are excluded).
| object | Object. |
Returns the type of the object.
Each object is an instance of a specific class type. The type handle returned by this function can be used to learn about the class.
| object | Object. |
Blocks until an incoming connection request is accepted.
| socket | A socket object in the listening state. |
| connection | Receives a socket object representing the newly-established connection, or kNULL. |
| allocator | Memory allocator (or kNULL for default). |
| kStatus kSocket_Bind | ( | kSocket | socket, |
| kIpAddress | address, | ||
| k32u | port | ||
| ) |
Binds the socket to a local IP address and/or port.
| socket | Destination for the constructed object handle. |
| address | A local IP address, or kIpAddress_Any(). |
| port | A local port number, or kIP_PORT_ANY. |
Binds the socket to a specific network interface.
This function was introduced to work around a UDP broadcast issue on QNX, and is not supported on all platforms.
| socket | Socket object. |
| interfaceName | Device name. |
| kStatus kSocket_Connect | ( | kSocket | socket, |
| kIpAddress | address, | ||
| k32u | port, | ||
| k64u | timeout | ||
| ) |
Connects the socket to a remote end point.
A connection can be attempted only once per socket object.
| socket | Socket object. |
| address | The remote IP address. |
| port | The remote port number. |
| timeout | The timeout interval, in microseconds. |
| kStatus kSocket_Construct | ( | kSocket * | socket, |
| kIpVersion | ipVersion, | ||
| kSocketType | socketType, | ||
| kAlloc | allocator | ||
| ) |
Constructs a kSocket object.
Note: Methods in the socket API are not thread-safe, unless otherwise noted.
| socket | Destination for the constructed object handle. |
| ipVersion | Internet Protocol version. |
| socketType | The type of socket to create (i.e. TCP or UDP). |
| allocator | Memory allocator (or kNULL for default). |
Enables or disables datagram broadcasting.
This function is typically used in conjunction with a UDP socket that is bound to a local address. Sending to kIpAddress_BroacastV4() will broadcast a datagram on the subnet associated with the bound IPv4 address.
| socket | Socket object. |
| broadcast | kTRUE to enable broadcasts; kFALSE otherwise. |
Enables or disables reuse of a local end point within a short period of time.
The option is typically used to allow a server to rebind to a local end point while a previous socket with the same local end point is in the TIME_WAIT state. This can be useful when a server must be stopped and started within a brief interval, but there is a small risk that packets with identical source/destination information could be misdirected to the new socket.
| socket | Socket object. |
| reuse | kTRUE to enable reuse of IP addresses; kFALSE otherwise. |
| kSocketEvent kSocket_Events | ( | kSocket | socket | ) |
Gets the events detected during the most recent wait operation.
| socket | Socket object. |
Places the socket into a listening state, to monitor for incoming connection requests.
| socket | Socket object. |
| backlog | The maximum number of pending connection requests to enqueue. |
| kStatus kSocket_LocalEndPoint | ( | kSocket | socket, |
| kIpEndPoint * | endPoint | ||
| ) |
Returns the local end point for a bound socket.
| socket | Socket object. |
| endPoint | Local end point. |
Reads one or more bytes.
In blocking mode, this function will block until at least one byte is received (or a read timeout occurs).
In non-blocking mode, this function will read at least one byte. kSocket_Wait should be used to determine when this function can be called successfully.
If the socket was closed by the remote peer, this function will return kERROR_CLOSED.
| socket | Socket object. |
| buffer | Buffer to receive bytes. |
| size | The maximum number of bytes to read. |
| read | The number of bytes that were read. |
| kStatus kSocket_ReadFrom | ( | kSocket | socket, |
| kIpEndPoint * | endPoint, | ||
| void * | buffer, | ||
| kSize | size, | ||
| kSize * | read | ||
| ) |
Reads a datagram.
In blocking mode, this function will block until a datagram is read (or a read timeout occurs).
In non-blocking mode, kSocket_Wait should be used to determine when this function can be called successfully.
| socket | Socket object. |
| endPoint | The address of the sender. |
| buffer | Buffer to receive the datagram. |
| size | The maximum number of bytes to return. |
| read | The number of bytes that were read. |
| kStatus kSocket_RemoteEndPoint | ( | kSocket | socket, |
| kIpEndPoint * | endPoint | ||
| ) |
Returns the remote end point for a connected socket.
| socket | Socket object. |
| endPoint | Remote end point. |
Determines whether the socket will block on read/write requests.
By default, sockets are created in blocking mode.
| socket | Socket object. |
| isBlocking | If kTRUE, the socket will be placed in blocking mode. |
| kStatus kSocket_SetEvents | ( | kSocket | socket, |
| kSocketEvent | events | ||
| ) |
Sets the event types that a socket will wait on.
By default, sockets wait on read events.
| socket | Socket object. |
| events | One or more event types to wait on. |
Specifies the duration that a TCP connection can remain open when the socket is closed in order to ensure that all outbound bytes are transmitted to the receiver.
If the linger time is not set, then a default linger time will be selected by the underlying operating system.
| socket | Socket object. |
| lingerTime | Linger time, in microseconds (0 for immediate closure). |
Can be used to disable the Nagle algorithm.
The Nagle algorithm is enabled by default. When enabled, small segments of outbound data are coalesced over a brief time period in order to improve network efficiency.
| socket | Socket object. |
| noDelay | kTRUE to disable the Nagle algorithm; kFALSE to enable. |
Sets the size of the read buffer used by the underlying operating system.
| socket | Socket object. |
| size | Size of the read buffer. |
Sets the timeout duration for blocking read operations.
By default, kSocket objects do not use a timeout interval and can block indefinitely.
| socket | Socket object. |
| timeout | Timeout value, in microseconds. |
Sets the size of the write buffer used by the underlying operating system.
| socket | Socket object. |
| size | Size of the write buffer. |
Sets the timeout duration for blocking write operations.
By default, socket objects do not use a timeout interval and can block indefinitely.
| socket | Socket object. |
| timeout | Timeout value, in microseconds. |
Reports any internal errors that will prevent success of future communication attempts.
| socket | Socket object. |
Waits for a socket event.
Before calling this function, use kSocket_SetEvents to specify the events that the socket should wait on. After calling this function, use the kSocket_Events function to determine which events have occurred.
This function will return kERROR_TIMEOUT if no events occur by the end of the timeout period.
| socket | Socket object. |
| timeout | Timeout, in microseconds. |
Waits until an event occurs on one or more sockets.
Before calling this function, use kSocket_SetEvents to specify the events that the sockets should wait on. After calling this function, use the kSocket_Events function to determine which events have occurred.
This function will return kERROR_TIMEOUT if no socket events occur by the end of the timeout period.
| sockets | An array of sockets to wait on. |
| count | The number of sockets in the array. |
| timeout | Timeout, in microseconds. |
Writes one or more bytes.
In blocking mode, this function will block until all bytes are written (or a write timeout occurs).
In non-blocking mode, this function will write zero or more bytes. kSocket_Wait can be used to determine when buffer space is available for a write operation, increasing the odds that bytes can be written successfully.
| socket | Socket object. |
| buffer | Buffer of bytes to write. |
| size | The number of bytes to write. |
| written | The number of bytes that were written. |
| kStatus kSocket_WriteTo | ( | kSocket | socket, |
| kIpAddress | address, | ||
| k32u | port, | ||
| const void * | buffer, | ||
| kSize | size | ||
| ) |
Sends a datagram.
In blocking mode, this function will block until the datagram is sent (or a write timeout occurs).
In non-blocking mode, use kSocket_Wait to determine when this function can be called successfully.
| socket | Socket object. |
| address | IP address of the recipient. |
| port | Port number of the recipient. |
| buffer | Buffer containing the datagram to send. |
| size | The number of bytes in the supplied buffer. |