30 #ifndef PTLIB_SOCKET_H
31 #define PTLIB_SOCKET_H
43 #ifdef __NUCLEUS_PLUS__
44 #include <sys/socket.h>
104 unsigned queueSize = 5,
156 int level = SOL_SOCKET
167 const void * valuePtr,
169 int level = SOL_SOCKET
181 int level = SOL_SOCKET
194 int level = SOL_SOCKET
241 const char * protocol,
267 const char * protocol,
311 class SelectList :
public PSocketList
317 { DisallowDeleteObjects(); }
394 inline static WORD
Host2Net(WORD v) {
return htons(v); }
397 inline static DWORD
Host2Net(DWORD v) {
return htonl(v); }
400 inline static WORD
Net2Host(WORD v) {
return ntohs(v); }
402 inline static DWORD
Net2Host(DWORD v) {
return ntohl(v); }
411 struct Slice :
public WSABUF
414 { buf = (
char *)0; len = 0; }
416 Slice(
void * v,
const size_t len)
419 Slice(
const void * v,
const size_t len)
422 void SetBase(
const void * v) { buf = (
char *)v; }
423 void SetBase(
void * v) { buf = (
char *)v; }
424 void *
GetBase()
const {
return buf; }
426 void SetLength(
size_t v) { len = (ULONG)v; }
431 struct Slice :
public iovec
478 const Slice * slices,
497 int os_socket(
int af,
int type,
int proto);
499 struct sockaddr * sin,
507 struct sockaddr * from,
512 const Slice * slices,
515 struct sockaddr * to,
521 struct sockaddr * addr,
534 #include "msos/ptlib/socket.h"
536 #include "unix/ptlib/socket.h"
541 #endif // PTLIB_SOCKET_H
PBoolean os_connect(struct sockaddr *sin, socklen_t size)
static DWORD Host2Net(DWORD v)
Convert from host to network byte order.
Definition: socket.h:397
Slice(void *v, size_t len)
Definition: socket.h:444
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
PLIST(PSocketList, PSocket)
Error during other operation, eg Open()
Definition: channel.h:254
Slice()
Definition: socket.h:441
static WORD GetProtocolByName(const PString &name)
Get the number of the protocol associated with the specified name.
static int Select(PSocket &sock1, PSocket &sock2)
Select a socket with available data.
List of sockets used for Select() function.
Definition: socket.h:312
virtual PBoolean Shutdown(ShutdownValue option)
Close one or both of the data streams associated with a socket.
ShutdownValue
Definition: channel.h:589
void SetLength(size_t v)
Definition: socket.h:449
static PString GetNameByProtocol(WORD proto)
Get the name of the protocol number specified.
Errors
Normalised error codes.
Definition: channel.h:227
virtual PBoolean Connect(const PString &address)
Connect a socket to a remote host on the specified port number.
PBoolean os_accept(PSocket &listener, struct sockaddr *addr, socklen_t *size)
static DWORD Net2Host(DWORD v)
Convert from network to host byte order.
Definition: socket.h:402
virtual PString GetServiceByPort(WORD port) const
Get the service name from the port number.
PBoolean GetOption(int option, int &value, int level=SOL_SOCKET)
Get options on the socket.
virtual int os_errno() const
PBoolean os_vwrite(const Slice *slices, size_t sliceCount, int flags, struct sockaddr *to, socklen_t tolen)
virtual PBoolean OpenSocket()=0
static WORD Host2Net(WORD v)
Convert from host to network byte order.
Definition: socket.h:395
Abstract class defining I/O channel semantics.
Definition: channel.h:103
Structure that defines a "slice" of memory to be written to.
Definition: socket.h:434
bool PBoolean
Definition: object.h:174
virtual WORD GetPortByService(const PString &service) const
Get the port number for the specified service name.
WORD m_port
Port to be used by the socket when opening the channel.
Definition: socket.h:530
intptr_t P_INT_PTR
Definition: object.h:2646
The character string class.
Definition: pstring.h:108
void * iov_base
Definition: socket.h:437
ErrorGroup
Error groups.
Definition: channel.h:251
SelectList()
Definition: socket.h:316
void operator-=(PSocket &sock)
Remove a socket from list .
Definition: socket.h:322
PString GetService() const
Get a service name for the port number the TCP socket channel object instance is using.
void * GetBase() const
Definition: socket.h:448
virtual bool Read(Slice *slices, size_t sliceCount)
Low level scattered read from the channel.
PBoolean os_vread(Slice *slices, size_t sliceCount, int flags, struct sockaddr *from, socklen_t *fromlen)
void operator+=(PSocket &sock)
Add a socket to list .
Definition: socket.h:319
virtual bool Write(const Slice *slices, size_t sliceCount)
Low level scattered write to the channel.
size_t iov_len
Definition: socket.h:438
virtual const char * GetProtocolName() const =0
This function returns the protocol name for the socket type.
void SetBase(void *v)
Definition: socket.h:447
A network communications channel.
Definition: socket.h:59
static WORD Net2Host(WORD v)
Convert from network to host byte order.
Definition: socket.h:400
size_t GetLength() const
Definition: socket.h:450
virtual PBoolean ConvertOSError(P_INT_PTR libcReturnValue, ErrorGroup group=LastGeneralError)
Convert an operating system error into platform independent error.
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:85
PBoolean SetOption(int option, int value, int level=SOL_SOCKET)
Set options on the socket.
virtual PBoolean Listen(unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
Listen on a socket for a remote host on the specified port number.
virtual PBoolean Accept(PSocket &socket)
Open a socket to a remote host on the specified port number.
void SetPort(WORD port)
Set the port number for the channel.
int os_socket(int af, int type, int proto)
WORD GetPort() const
Get the port the TCP socket channel object instance is using.