libsocket
Public Member Functions | Protected Attributes | Friends | List of all members
libsocket::unix_stream_client Class Reference

Provides an interface for working with UNIX STREAM sockets. More...

#include <unixclientstream.hpp>

Inheritance diagram for libsocket::unix_stream_client:
Inheritance graph
[legend]

Public Member Functions

 unix_stream_client (void)
 Constructor. More...
 
 unix_stream_client (const char *path, int socket_flags=0)
 Constructor, setting up a connection. More...
 
 unix_stream_client (const string &path, int socket_flags=0)
 Constructor, setting up a connection. More...
 
void connect (const char *path, int socket_flags=0)
 Connect socket. More...
 
void connect (const string &path, int socket_flags=0)
 Connect socket. More...
 
string get_path (void)
 Returns the path we're bound or connected to. More...
 
virtual int destroy (void)
 Destroys a socket. More...
 
int getfd (void) const
 Returns the socket file descriptor. More...
 
int set_sock_opt (int level, int optname, const char *optval, socklen_t optlen) const
 Set socket options on the underlying socket. More...
 
void set_close_on_destructor (bool cod)
 
ssize_t snd (const void *buf, size_t len, int flags=0)
 Send data to socket. More...
 
ssize_t rcv (void *buf, size_t len, int flags=0)
 Receive data from socket. More...
 
void shutdown (int method=LIBSOCKET_WRITE)
 Shut a socket down. More...
 

Protected Attributes

string _path
 
int sfd
 sfd is the sockets API file descriptor More...
 
bool is_nonblocking
 
bool close_on_destructor
 
bool shut_rd
 
bool shut_wr
 

Friends

class unix_stream_server
 

Detailed Description

Provides an interface for working with UNIX STREAM sockets.

Definition at line 49 of file unixclientstream.hpp.

Constructor & Destructor Documentation

◆ unix_stream_client() [1/3]

libsocket::unix_stream_client::unix_stream_client ( void  )

Constructor.

Definition at line 55 of file unixclientstream.cpp.

◆ unix_stream_client() [2/3]

libsocket::unix_stream_client::unix_stream_client ( const char *  path,
int  socket_flags = 0 
)

Constructor, setting up a connection.

Constructs a UNIX stream client socket and connects it.

Parameters
pathPeer (server) socket.
socket_flagsFlags for socket(2)

Definition at line 65 of file unixclientstream.cpp.

Here is the call graph for this function:

◆ unix_stream_client() [3/3]

libsocket::unix_stream_client::unix_stream_client ( const string &  path,
int  socket_flags = 0 
)

Constructor, setting up a connection.

Constructs a UNIX stream client socket and connects it.

Parameters
pathPeer (server) socket.
socket_flagsFlags for socket(2)

Definition at line 77 of file unixclientstream.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ connect() [1/2]

void libsocket::unix_stream_client::connect ( const char *  path,
int  socket_flags = 0 
)

Connect socket.

Connects a client stream socket.

Parameters
pathThe server socket's path
socket_flagsFlags for socket(2) (Do I repeat myself?)

Definition at line 89 of file unixclientstream.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect() [2/2]

void libsocket::unix_stream_client::connect ( const string &  path,
int  socket_flags = 0 
)

Connect socket.

Connects a client stream socket.

Parameters
pathThe server socket's path
socket_flagsFlags for socket(2) (Do I repeat myself?)

Definition at line 117 of file unixclientstream.cpp.

Here is the call graph for this function:

◆ get_path()

string libsocket::unix_socket::get_path ( void  )
inherited

Returns the path we're bound or connected to.

Definition at line 50 of file unixbase.cpp.

◆ destroy()

int libsocket::socket::destroy ( void  )
virtualinherited

Destroys a socket.

Return values
0Fine!
<0Most likely the socket was already closed before.

Definition at line 72 of file socket.cpp.

Here is the caller graph for this function:

◆ getfd()

int libsocket::socket::getfd ( void  ) const
inherited

Returns the socket file descriptor.

Returns
The socket file descriptor of the class.

getfd() is a getter you may use to obtain the file descriptor for raw operations on it. It's relatively uncritical as libsocket just wraps other syscalls and doesn't manipulate it using unusual ways.

Definition at line 91 of file socket.cpp.

◆ set_sock_opt()

int libsocket::socket::set_sock_opt ( int  level,
int  optname,
const char *  optval,
socklen_t  optlen 
) const
inherited

Set socket options on the underlying socket.

Returns
The return value of setsockopt(2).

Sets socket options using setsockopt(2). See setsockopt(2), tcp(7), udp(7), unix(7) for documentation on how to use this function.

Definition at line 101 of file socket.cpp.

◆ set_close_on_destructor()

void libsocket::socket::set_close_on_destructor ( bool  cod)
inlineinherited

close_on_destructor is true by default. If set to false, do not call close(2) on the underlying socket in the destructor.

Definition at line 95 of file socket.hpp.

◆ snd()

ssize_t libsocket::stream_client_socket::snd ( const void *  buf,
size_t  len,
int  flags = 0 
)
inherited

Send data to socket.

Parameters
bufData to be sent
lenLength of buf
flagsFlags for send(2). WARNING: Throws an exception if send() returns -1; this may be the case if the flag MSG_DONTWAIT is used.
Returns
The number of bytes sent to the peer. -1 if the socket is non-blocking and no data was sent.

Definition at line 243 of file streamclient.cpp.

◆ rcv()

ssize_t libsocket::stream_client_socket::rcv ( void *  buf,
size_t  len,
int  flags = 0 
)
inherited

Receive data from socket.

...and puts it in buf.

Parameters
bufA writable memory buffer of length len
lenLength of buf
flagsFlags for recv(2). WARNING: Throws an exception if recv() returns -1; this may be the case if the flag MSG_DONTWAIT is used.
Returns
The length of received data

Definition at line 68 of file streamclient.cpp.

◆ shutdown()

void libsocket::stream_client_socket::shutdown ( int  method = LIBSOCKET_WRITE)
inherited

Shut a socket down.

Shuts a socket down using shutdown(2).

Parameters
methodLIBSOCKET_READ/LIBSOCKET_WRITE or an ORed combination.

Definition at line 279 of file streamclient.cpp.

Friends And Related Function Documentation

◆ unix_stream_server

friend class unix_stream_server
friend

unix_stream_server returns pointer to unix_stream_client objects when accepting connections.

Definition at line 58 of file unixclientstream.hpp.

Member Data Documentation

◆ _path

string libsocket::unix_socket::_path
protectedinherited

The path we're connected (client stream) or bound (server stream, server datagram)

Definition at line 55 of file unixbase.hpp.

◆ sfd

int libsocket::socket::sfd
protectedinherited

sfd is the sockets API file descriptor

Definition at line 74 of file socket.hpp.

◆ close_on_destructor

bool libsocket::socket::close_on_destructor
protectedinherited

Default is true; if set to false, the file descriptor is not closed when the destructor is called.

Definition at line 78 of file socket.hpp.

◆ shut_rd

bool libsocket::stream_client_socket::shut_rd
protectedinherited

If the socket was shut down for reading (-> no reads anymore)

Definition at line 54 of file streamclient.hpp.

◆ shut_wr

bool libsocket::stream_client_socket::shut_wr
protectedinherited

If the socket was shut down for writing (-> no writes anymore)

Definition at line 56 of file streamclient.hpp.


The documentation for this class was generated from the following files: