EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Socket Class Reference

Simple wrapper for sockets. More...

#include "Socket.h"

Public Member Functions

 Socket (int af, int type, int protocol)
 
 ~Socket ()
 
int connect (const sockaddr *name, unsigned int namelen)
 
unsigned int recv (void *buf, unsigned int len, int flags)
 
unsigned int recvfrom (void *buf, unsigned int len, int flags, sockaddr *from, unsigned int *fromlen)
 
unsigned int send (const void *buf, unsigned int len, int flags)
 
unsigned int sendto (const void *buf, unsigned int len, int flags, const sockaddr *to, unsigned int tolen)
 
int bind (const sockaddr *name, unsigned int namelen)
 
int listen (int backlog=SOMAXCONN)
 
Socketaccept (sockaddr *addr, unsigned int *addrlen)
 
int setopt (int level, int optname, const void *optval, unsigned int optlen)
 
int fcntl (int cmd, long arg)
 

Protected Member Functions

 Socket (SOCKET sock)
 

Protected Attributes

SOCKET mSock
 

Detailed Description

Simple wrapper for sockets.

Author
Bloody.Rabbit

Definition at line 34 of file Socket.h.

Constructor & Destructor Documentation

Socket::Socket ( int  af,
int  type,
int  protocol 
)

Definition at line 30 of file Socket.cpp.

References INVALID_SOCKET, and mSock.

Referenced by accept().

32 {
33  // Create new socket
34  mSock = ::socket( af, type, protocol );
35 
36  // Verify socket
37  assert( mSock != INVALID_SOCKET );
38 }
SOCKET mSock
Definition: Socket.h:58
#define INVALID_SOCKET
Definition: eve-compat.h:129

Here is the caller graph for this function:

Socket::~Socket ( )

Definition at line 47 of file Socket.cpp.

References mSock.

48 {
49  ::shutdown( mSock, SHUT_RD );
50  ::shutdown( mSock, SHUT_WR );
51  ::close( mSock );
52 }
SOCKET mSock
Definition: Socket.h:58
Socket::Socket ( SOCKET  sock)
protected

Definition at line 40 of file Socket.cpp.

References INVALID_SOCKET, and mSock.

41 : mSock( sock )
42 {
43  // Verify socket
44  assert( mSock != INVALID_SOCKET );
45 }
SOCKET mSock
Definition: Socket.h:58
#define INVALID_SOCKET
Definition: eve-compat.h:129

Member Function Documentation

Socket * Socket::accept ( sockaddr *  addr,
unsigned int *  addrlen 
)

Definition at line 89 of file Socket.cpp.

References INVALID_SOCKET, mSock, and Socket().

Referenced by BaseTCPServer::ListenNewConnections().

90 {
91  SOCKET sock = ::accept( mSock, addr, addrlen );
92 
93  if( sock != INVALID_SOCKET )
94  return new Socket( sock );
95  else
96  return nullptr;
97 }
SOCKET mSock
Definition: Socket.h:58
Socket(int af, int type, int protocol)
Definition: Socket.cpp:30
#define INVALID_SOCKET
Definition: eve-compat.h:129
Socket * accept(sockaddr *addr, unsigned int *addrlen)
Definition: Socket.cpp:89
int SOCKET
Definition: eve-compat.h:127

Here is the call graph for this function:

Here is the caller graph for this function:

int Socket::bind ( const sockaddr *  name,
unsigned int  namelen 
)

Definition at line 79 of file Socket.cpp.

References mSock.

Referenced by BaseTCPServer::Open().

80 {
81  return ::bind( mSock, name, namelen );
82 }
SOCKET mSock
Definition: Socket.h:58

Here is the caller graph for this function:

int Socket::connect ( const sockaddr *  name,
unsigned int  namelen 
)

Definition at line 54 of file Socket.cpp.

References mSock.

Referenced by TCPConnection::Connect().

55 {
56  return ::connect( mSock, name, namelen );
57 }
SOCKET mSock
Definition: Socket.h:58

Here is the caller graph for this function:

int Socket::fcntl ( int  cmd,
long  arg 
)

Definition at line 104 of file Socket.cpp.

References mSock.

Referenced by TCPConnection::Connect(), BaseTCPServer::ListenNewConnections(), and BaseTCPServer::Open().

105 {
106  return ::fcntl( mSock, cmd, arg );
107 }
SOCKET mSock
Definition: Socket.h:58

Here is the caller graph for this function:

int Socket::listen ( int  backlog = SOMAXCONN)

Definition at line 84 of file Socket.cpp.

References mSock.

Referenced by BaseTCPServer::Open().

85 {
86  return ::listen( mSock, backlog );
87 }
SOCKET mSock
Definition: Socket.h:58

Here is the caller graph for this function:

unsigned int Socket::recv ( void *  buf,
unsigned int  len,
int  flags 
)

Definition at line 59 of file Socket.cpp.

References mSock.

Referenced by TCPConnection::RecvData().

60 {
61  return ::recv( mSock, (char*)buf, len, flags );
62 }
SOCKET mSock
Definition: Socket.h:58

Here is the caller graph for this function:

unsigned int Socket::recvfrom ( void *  buf,
unsigned int  len,
int  flags,
sockaddr *  from,
unsigned int *  fromlen 
)

Definition at line 64 of file Socket.cpp.

References mSock.

65 {
66  return ::recvfrom( mSock, buf, len, flags, from, fromlen );
67 }
SOCKET mSock
Definition: Socket.h:58
unsigned int Socket::send ( const void *  buf,
unsigned int  len,
int  flags 
)

Definition at line 69 of file Socket.cpp.

References mSock.

Referenced by TCPConnection::SendData().

70 {
71  return ::send( mSock, (const char*)buf, len, flags );
72 }
SOCKET mSock
Definition: Socket.h:58

Here is the caller graph for this function:

unsigned int Socket::sendto ( const void *  buf,
unsigned int  len,
int  flags,
const sockaddr *  to,
unsigned int  tolen 
)

Definition at line 74 of file Socket.cpp.

References mSock.

75 {
76  return ::sendto( mSock, (const char*)buf, len, flags, to, tolen );
77 }
SOCKET mSock
Definition: Socket.h:58
int Socket::setopt ( int  level,
int  optname,
const void *  optval,
unsigned int  optlen 
)

Definition at line 99 of file Socket.cpp.

References mSock.

Referenced by TCPConnection::Connect(), BaseTCPServer::ListenNewConnections(), and BaseTCPServer::Open().

100 {
101  return ::setsockopt( mSock, level, optname, (const char*)optval, optlen );
102 }
SOCKET mSock
Definition: Socket.h:58

Here is the caller graph for this function:

Member Data Documentation

SOCKET Socket::mSock
protected

Definition at line 58 of file Socket.h.

Referenced by accept(), bind(), connect(), fcntl(), listen(), recv(), recvfrom(), send(), sendto(), setopt(), Socket(), and ~Socket().


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