ui-utilcpp 1.10.1
Public Member Functions
UI::Util::Socket Class Reference

Socket abstraction. More...

#include <Socket.hpp>

Inheritance diagram for UI::Util::Socket:
Inheritance graph
Collaboration diagram for UI::Util::Socket:
Collaboration graph

Public Member Functions

 Socket (int fd=-1, bool closeFd=false)
 Construct socket.
 
std::string getId (bool const &peer=false) const
 Get human-readable id string.
 
std::string getPeerId () const
 Get peer id.
 
virtual Socketconnect ()
 Connect this socket. More...
 
virtual Socketbind ()
 Bind this socket. More...
 
Socketlisten (int backlog=16)
 Start listening.
 
int accept (long int toSeconds=0, long int toMicroSeconds=0)
 Accept an incoming socket connection.
 
int shutdown (int how, bool doThrow=true)
 Shutdown socket.
 
virtual std::streamsize read (void *const buf, std::streamsize count)
 C++-like virtual read method. More...
 
virtual std::streamsize write (void const *const buf, std::streamsize count)
 C++-like virtual write method. More...
 
Configure socket behaviour.
SocketsetRcvTimeout (long int seconds, long int microseconds=0)
 
SocketsetSndTimeout (long int seconds, long int microseconds=0)
 
SocketsetUnblock (bool unblock=true)
 
Wrappers for recv(2) and send(2).
ssize_t recv (void *const buf, size_t len, int flags=0)
 
ssize_t send (void const *const msg, size_t len, int flags=0)
 
- Public Member Functions inherited from UI::Util::FileDescriptor
 FileDescriptor (int fd=-1, bool closeFd=false)
 Constructor from file descriptor. More...
 
virtual ~FileDescriptor ()
 Destructor. More...
 
virtual std::streamsize read (void *const buf, std::streamsize count)
 C++ like virtual read method. More...
 
virtual std::streamsize write (void const *const buf, std::streamsize count)
 C++ like virtual erite method. More...
 
int getFd () const
 Get file descriptor.
 

Additional Inherited Members

- Public Types inherited from UI::Util::FileDescriptor
enum  ErrorCode {
  OpenErr_ = 1 , ReadErr_ , WriteErr_ , LockErr_ ,
  UnlockErr_ , BindErr_ , ConnectErr_ , UnblockErr_ ,
  ListenErr_ , ShutdownErr_
}
 Error codes for exceptions.
 
typedef CodeException< ErrorCodeException
 Exceptions for this class.
 
- Static Public Member Functions inherited from UI::Util::FileDescriptor
static void fdClose (int const &fd, std::string const &id, bool const &doClose=true)
 Helper to close file descriptors from destructors.
 
- Protected Member Functions inherited from UI::Util::FileDescriptor
void init (int fd, bool closeFd=false)
 To be called in a constructor.
 
- Protected Attributes inherited from UI::Util::FileDescriptor
int fd_
 The file descriptor that is managed.
 

Detailed Description

Socket abstraction.

Examples
EchoServer.cpp.

Member Function Documentation

◆ bind()

Socket & UI::Util::Socket::bind ( )
virtual

Bind this socket.

Reimplemented in UI::Util::INetSocket, and UI::Util::UnixSocket.

Examples
EchoServer.cpp.

References getId(), and UI_THROW_CODE.

◆ connect()

Socket & UI::Util::Socket::connect ( )
virtual

Connect this socket.

Reimplemented in UI::Util::INetSocket, and UI::Util::UnixSocket.

Examples
EchoServer.cpp.

References getId(), and UI_THROW_CODE.

◆ read()

std::streamsize UI::Util::Socket::read ( void *const  buf,
std::streamsize  count 
)
virtual

C++-like virtual read method.

This implementation uses recv(2).

Reimplemented from UI::Util::FileDescriptor.

References getId(), and UI_THROW_CODE.

◆ write()

std::streamsize UI::Util::Socket::write ( void const *const  buf,
std::streamsize  count 
)
virtual

C++-like virtual write method.

This implementation uses send(2).

Reimplemented from UI::Util::FileDescriptor.

References getId(), and UI_THROW_CODE.


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