Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ServerSocketTCP Class Reference

#include <vsnet_serversocket.h>

Inheritance diagram for ServerSocketTCP:
ServerSocket VsnetSocketBase

Public Member Functions

 ServerSocketTCP (int fd, const AddressIP &adr, SocketSet &set)
 
virtual bool isActive ()
 
virtual SOCKETALT acceptNewConn ()
 
virtual bool lower_selected (int datalen=-1)
 
- Public Member Functions inherited from ServerSocket
 ServerSocket (int fd, const AddressIP &adr, const char *socktype, SocketSet &set)
 
const AddressIPget_adr () const
 
- Public Member Functions inherited from VsnetSocketBase
 VsnetSocketBase (int fd, const char *socktype, SocketSet &set)
 
virtual ~VsnetSocketBase ()
 
bool valid () const
 
int get_fd () const
 
int close_fd ()
 
const char * get_socktype () const
 
bool set_block ()
 
bool set_nonblock ()
 
bool get_nonblock () const
 
void disconnect (const char *s)
 
virtual bool need_test_writable ()
 
virtual bool write_on_negative ()
 
virtual int get_write_fd () const
 
virtual int lower_sendbuf ()
 
virtual void lower_clean_sendbuf ()
 
virtual bool isReadyToSend (fd_set *)
 
void setSet (SocketSet *set)
 

Additional Inherited Members

- Protected Member Functions inherited from ServerSocket
virtual void child_disconnect (const char *s)
 
- Protected Attributes inherited from ServerSocket
AddressIP _srv_ip
 

Detailed Description

Definition at line 58 of file vsnet_serversocket.h.

Constructor & Destructor Documentation

ServerSocketTCP::ServerSocketTCP ( int  fd,
const AddressIP adr,
SocketSet set 
)

Definition at line 65 of file vsnet_serversocket.cpp.

References ServerSocketTCP().

Referenced by ServerSocketTCP().

65  :
66  ServerSocket( fd, adr, "ServerSocketTCP", set )
67 {}

Member Function Documentation

SOCKETALT ServerSocketTCP::acceptNewConn ( )
virtual

Implements ServerSocket.

Definition at line 77 of file vsnet_serversocket.cpp.

References VsnetSocketBase::_set, COUT, VsnetSocketBase::get_fd(), VSMutex::lock(), SocketSet::rem_pending(), and VSMutex::unlock().

78 {
79  _ac_mx.lock();
80  if ( !_accepted_connections.empty() ) {
81  COUT<<"A connection has been accepted"<<endl;
82  SOCKETALT ret( _accepted_connections.front() );
83  _accepted_connections.pop();
84  _ac_mx.unlock();
85  return ret;
86  } else {
87  COUT<<"No accepted TCP connection"<<endl;
88  _ac_mx.unlock();
89  if (_set) _set->rem_pending( get_fd() );
90  SOCKETALT ret;
91  return ret;
92  }
93 }
bool ServerSocketTCP::isActive ( )
virtual

Implements VsnetSocketBase.

Definition at line 69 of file vsnet_serversocket.cpp.

References VSMutex::lock(), and VSMutex::unlock().

70 {
71  _ac_mx.lock();
72  bool ret = (_accepted_connections.empty() == false);
73  _ac_mx.unlock();
74  return ret;
75 }
bool ServerSocketTCP::lower_selected ( int  datalen = -1)
virtual

Implements VsnetSocketBase.

Definition at line 32 of file vsnet_serversocket.cpp.

References VsnetSocketBase::_set, SocketSet::add_pending(), COUT, VsnetSocketBase::get_fd(), VSMutex::lock(), VSMutex::unlock(), and vsnetLastError().

33 {
34  COUT<<endl
35  <<endl
36  <<"------------------------------------------"<<endl
37  <<"ServerSocketTCP for "<<get_fd()<<" selected"<<endl
38  <<"------------------------------------------"<<endl
39  <<endl
40  <<endl;
41 
42  struct sockaddr_in remote_ip;
43 #if defined (_WIN32) || defined (MAC_OS_X_VERSION_10_3) || defined (MAC_OS_X_VERSION_10_2) || defined (MAC_OS_X_VERSION_10_1)
44  int
45 #else
46  socklen_t
47 #endif
48  len = sizeof (struct sockaddr_in);
49  int sock = ::accept( get_fd(), (sockaddr*) &remote_ip, &len );
50  if (sock > 0) {
51  COUT<<"accepted new sock "<<sock<<endl;
52  SOCKETALT newsock( sock, SOCKETALT::TCP, remote_ip, *_set );
53  _ac_mx.lock();
54  _accepted_connections.push( newsock );
55  _ac_mx.unlock();
56  if (_set) _set->add_pending( get_fd() );
57  return true;
58  } else {
59  COUT<<"accept failed"<<endl;
60  COUT<<"Error accepting new conn: "<<vsnetLastError()<<endl;
61  return false;
62  }
63 }

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