the_Foundation 1.0
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
socket.h File Reference
#include "stream.h"
#include "address.h"

Typedefs

typedef iStreamClass iSocketClass
 
typedef struct Impl_Socket iSocket
 
typedef void(* iNotifySocketConnected) (iAny *, iSocket *)
 
typedef void(* iNotifySocketDisconnected) (iAny *, iSocket *)
 
typedef void(* iNotifySocketError) (iAny *, iSocket *, int error, const char *msg)
 
typedef void(* iNotifySocketReadyRead) (iAny *, iSocket *)
 
typedef void(* iNotifySocketBytesWritten) (iAny *, iSocket *, size_t numBytes)
 
typedef void(* iNotifySocketWriteFinished) (iAny *, iSocket *)
 

Enumerations

enum  iSocketStatus {
  addressLookup_SocketStatus , initialized_SocketStatus , connecting_SocketStatus , connected_SocketStatus ,
  disconnecting_SocketStatus , disconnected_SocketStatus
}
 

Functions

iAudience * connected_Socket (iSocket *d)
 
iAudience * disconnected_Socket (iSocket *d)
 
iAudience * error_Socket (iSocket *d)
 
iAudience * readyRead_Socket (iSocket *d)
 
iAudience * bytesWritten_Socket (iSocket *d)
 
iAudience * writeFinished_Socket (iSocket *d)
 
iSocket * new_Socket (const char *hostName, uint16_t port)
 
void init_Socket (iSocket *d, const char *hostName, uint16_t port)
 
void deinit_Socket (iSocket *d)
 
iSocket * newAddress_Socket (const iAddress *address)
 
iSocket * newExisting_Socket (int fd, const void *sockAddr, size_t sockAddrSize)
 
iBool open_Socket (iSocket *)
 
void close_Socket (iSocket *)
 
iBool isOpen_Socket (const iSocket *)
 
enum iSocketStatus status_Socket (const iSocket *)
 
size_t receivedBytes_Socket (const iSocket *)
 
size_t bytesToSend_Socket (const iSocket *)
 
const iAddress * address_Socket (const iSocket *)
 

Detailed Description

TCP socket.

Socket is a bidirectional non-random-access Stream where data gets written by a background I/O thread.

Every time something gets written to the Socket's output buffer, the I/O thread is woken up and the pending data is sent. You may wish to use another Buffer to queue up data to send in larger chunks.

Socket is derived from Stream, so all Stream methods can be used on it for writing and reading data. Both reading and writing is non-blocking. When writing, a copy of the data is made into an internal buffer for the I/O thread. When reading, only data already received and waiting in the input buffer will be returned. To wait for incoming data you can join the readyRead audience.

Authors
Copyright (c) 2017 Jaakko Keränen jaakk.nosp@m.o.ke.nosp@m.ranen.nosp@m.@iki.nosp@m..fi
License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.