class::inet::Socket

class inet::Socket
  : public fs::File

The Socket class is for accessing websockets that run on the TCP/IP stack.

For a client, the typical exchange looks like this:

Note left of Client: Create Socket
Client->Server: connect()
Note right of Server: accept() and bind()
Client->Server: write()
Server->Client: read()
Client->Server: close()

Summary

Socket()

~Socket()

Socket accept(

arg::DestinationSocketAddress address
) const

virtual int bind(

const arg::SourceSocketAddress address
) const

virtual int bind_and_listen(

const arg::SourceSocketAddress address,
const arg::ListenBacklogCount backlog
) const

virtual int close()

virtual int connect(

const arg::SourceSocketAddress address
)

virtual int create(

const arg::SourceSocketAddress address
)

bool is_valid() const

Socket & operator<<(

const SocketOption & option
)

virtual int read(

arg::DestinationBuffer buf,
const arg::Size size
) const

int read(

arg::DestinationData data,
arg::DestinationSocketAddress address
)

int read(

arg::DestinationBuffer buf,
const arg::Size nbyte,
arg::DestinationSocketAddress address
)

int read(

arg::DestinationBuffer buf,
const arg::Size nbyte,
struct sockaddr * ai_addr,
socklen_t * ai_addrlen
) const

virtual int shutdown(

const fs::OpenFlags how
) const

virtual int write(

const arg::SourceBuffer buf,
const arg::Size size
) const

int write(

const arg::SourceData data,
const arg::SourceSocketAddress address
)

int write(

const arg::SourceBuffer buf,
const arg::Size nbyte,
const struct sockaddr * ai_addr,
socklen_t ai_addrlen
) const

int write(

const arg::SourceBuffer buf,
const arg::Size nbyte,
const arg::SourceSocketAddress socket_address
) const

static int deinitialize()

static int initialize()

Members

Socket()

~Socket()

Socket accept(

arg::DestinationSocketAddress address
) const

Accepts a socket connection on a socket that is listening.

Returns

A valid Socket if the operation is successful.


virtual int bind(

const arg::SourceSocketAddress address
) const


virtual int bind_and_listen(

const arg::SourceSocketAddress address,
const arg::ListenBacklogCount backlog
) const

Binds and listens to the port for which the socket was created.

Returns

Less than zero on error and zero on success

This method will always bind but it will only listen when using TCP sockets where listen is applicable.


virtual int close()

Closes the file or device.


virtual int connect(

const arg::SourceSocketAddress address
)

Connects to the server using the SocketAddress object passed to create() method.

Returns

Less than zero on error or zero on success


virtual int create(

const arg::SourceSocketAddress address
)

Creates a new socket.

@params attributes The Socket Attributes

Returns

Zero on success


bool is_valid() const

Socket & operator<<(

const SocketOption & option
)

Sets options for the socket.

Parameters

  • option The option to set for the socket
SocketAddressIpv4 address(0, 8080);
Socket socket;
socket.create(address);
socket << SocketOption().set_reuse_address() << SocketOption().set_reuse_port();
socket.bind(address);

virtual int read(

arg::DestinationBuffer buf,
const arg::Size size
) const

Reads the file.

Parameters

  • buf A pointer to the destination buffer

  • nbyte The number of bytes to read

Returns

The number of bytes read or less than zero on an error


int read(

arg::DestinationData data,
arg::DestinationSocketAddress address
)


int read(

arg::DestinationBuffer buf,
const arg::Size nbyte,
arg::DestinationSocketAddress address
)


int read(

arg::DestinationBuffer buf,
const arg::Size nbyte,
struct sockaddr * ai_addr,
socklen_t * ai_addrlen
) const


virtual int shutdown(

const fs::OpenFlags how
) const

Shuts down the socket.

Parameters

  • how Use READWRITE, READONLY, or WRITEONLY to disable the specified operations
Socket s;
s.shutdown(); //disables further send/receive operations
s.shutdown(Socket::READWRITE); //disables further send/receive operations
s.shutdown(Socket::WRITEONLY); //disables further send operations
s.shutdown(Socket::READONLY); //disables further receive operations

Returns

Zero on success


virtual int write(

const arg::SourceBuffer buf,
const arg::Size size
) const

Write the file.

Parameters

  • buf A pointer to the source buffer

  • nbyte The number of bytes to read

Returns

The number of bytes written or less than zero on an error


int write(

const arg::SourceData data,
const arg::SourceSocketAddress address
)

Parameters

  • data The data to write

  • address The address to write to.

This method implements the socket call sendto().


int write(

const arg::SourceBuffer buf,
const arg::Size nbyte,
const struct sockaddr * ai_addr,
socklen_t ai_addrlen
) const


int write(

const arg::SourceBuffer buf,
const arg::Size nbyte,
const arg::SourceSocketAddress socket_address
) const


static int deinitialize()

static int initialize()

X

Thanks for Coming!

Subscribe to news and updates