Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
|
#include <vsnet_sockettcp.h>
Classes | |
struct | Blob |
struct | Header |
class | SqQueues |
Public Types | |
typedef boost::shared_ptr< Packet > | PacketPtr |
Public Member Functions | |
VsnetTCPSocket (int sock, const AddressIP &remote_ip, SocketSet &set) | |
virtual | ~VsnetTCPSocket () |
virtual bool | isTcp () const |
virtual int | optPayloadSize () const |
virtual int | queueLen (int pri) |
virtual int | sendbuf (Packet *packet, const AddressIP *to, int pcktflags) |
virtual int | recvbuf (Packet *p, AddressIP *ipadr) |
virtual void | dump (std::ostream &ostr) const |
virtual bool | isActive () |
virtual bool | lower_selected (int datalen=-1) |
virtual bool | need_test_writable () |
virtual int | get_write_fd () const |
virtual int | lower_sendbuf () |
virtual void | lower_clean_sendbuf () |
![]() | |
VsnetSocket (int sock, const AddressIP &remote_ip, const char *socktype, SocketSet &set) | |
virtual | ~VsnetSocket () |
bool | eq (const VsnetSocket &r) const |
bool | lt (const VsnetSocket &r) const |
bool | sameAddress (const VsnetSocket &r) const |
const AddressIP & | getRemoteAddress () const |
virtual bool | setRemoteAddress (const AddressIP &) |
const AddressIP & | getLocalAddress () const |
bool | setLocalAddress (const AddressIP &lip) |
![]() | |
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 | write_on_negative () |
virtual bool | isReadyToSend (fd_set *) |
void | setSet (SocketSet *set) |
Protected Types | |
typedef std::queue< PacketPtr > | SqQueue |
typedef std::queue< PacketMem > | SqQueueP |
Protected Member Functions | |
virtual void | child_disconnect (const char *s) |
void | inc_pending () |
void | dec_pending () |
void | inner_complete_a_packet (Blob *b) |
void | private_nothread_conditional_write () |
Protected Attributes | |
Blob * | _incomplete_packet |
std::queue< PacketPtr > | _cpq |
cpq = completed packet queue More... | |
VSMutex | _cpq_mx |
int | _incomplete_header |
Header | _header |
bool | _connection_closed |
SqQueues | _sq |
SqQueueP | _sq_current |
size_t | _sq_off |
VSMutex | _sq_mx |
int | _sq_fd |
![]() | |
AddressIP | _remote_ip |
AddressIP | _local_ip |
![]() | |
int | _fd |
SocketSet * | _set |
Definition at line 26 of file vsnet_sockettcp.h.
typedef boost::shared_ptr< Packet > VsnetTCPSocket::PacketPtr |
Definition at line 30 of file vsnet_sockettcp.h.
|
protected |
TCP may refuse to send all bytes at once, hence we have to queue packets for sending. In addition, we use the same thread for sending and receiving, thus it would be advantageous to use asynchronous sending. For both, we need a send queue. _sq is the a of priority queues. _sq_current is the queue (with up to two entries) for sending the current packet, which consists of the packet length and the packet payload. _sq.off is the number of bytes that have already been sent from PacketMem _sq_current.front(). _sq_mx protects the queues.
Definition at line 138 of file vsnet_sockettcp.h.
|
protected |
Definition at line 139 of file vsnet_sockettcp.h.
Definition at line 63 of file vsnet_sockettcp.cpp.
References _sq_fd, COUT, and VsnetTCPSocket().
Referenced by VsnetTCPSocket().
|
virtual |
Definition at line 75 of file vsnet_sockettcp.cpp.
References _connection_closed, _incomplete_packet, VsnetSocketBase::close_fd(), COUT, VsnetSocketBase::get_fd(), and VsnetSocketBase::valid().
|
protectedvirtual |
Reimplemented from VsnetSocketBase.
Definition at line 295 of file vsnet_sockettcp.cpp.
References VsnetSocketBase::close_fd(), COUT, and VsnetSocketBase::get_fd().
|
protected |
|
virtual |
Implements VsnetSocket.
Definition at line 307 of file vsnet_sockettcp.cpp.
References VsnetSocket::_remote_ip, and VsnetSocketBase::get_fd().
|
virtual |
Reimplemented from VsnetSocketBase.
Definition at line 146 of file vsnet_sockettcp.cpp.
References _sq_fd.
|
protected |
The number of pending packets reported to the set.
|
protected |
Definition at line 457 of file vsnet_sockettcp.cpp.
References _cpq, _cpq_mx, VsnetSocketBase::_set, _sq_fd, SocketSet::add_pending(), b, VsnetTCPSocket::Blob::buf, VsnetTCPSocket::Blob::expected_len, VSMutex::lock(), VsnetTCPSocket::Blob::present_len, and VSMutex::unlock().
Referenced by lower_selected().
|
virtual |
Implements VsnetSocketBase.
Definition at line 318 of file vsnet_sockettcp.cpp.
References _connection_closed, _cpq, _cpq_mx, VsnetSocketBase::_set, _sq_fd, VSMutex::lock(), private_nothread_conditional_write(), SocketSet::rem_pending(), and VSMutex::unlock().
|
inlinevirtual |
|
virtual |
Called when we noticed that the primary file descriptor is closed but data remains in the send queue.
Reimplemented from VsnetSocketBase.
Definition at line 251 of file vsnet_sockettcp.cpp.
References _sq, _sq_current, _sq_mx, _sq_off, COUT, VsnetTCPSocket::SqQueues::empty(), VSMutex::lock(), VsnetTCPSocket::SqQueues::pop(), and VSMutex::unlock().
Implements VsnetSocketBase.
Definition at line 343 of file vsnet_sockettcp.cpp.
References _connection_closed, _header, _incomplete_header, _incomplete_packet, VsnetSocketBase::_set, _sq_fd, SocketSet::add_pending(), b, VsnetTCPSocket::Blob::base(), VsnetTCPSocket::Blob::buf, VsnetSocketBase::close_fd(), COUT, PacketMem::dump(), VsnetTCPSocket::Blob::expected_len, VsnetSocketBase::get_fd(), VsnetSocketBase::get_nonblock(), VsnetTCPSocket::Header::h_len(), i, inner_complete_a_packet(), VsnetTCPSocket::Blob::missing(), VsnetTCPSocket::Blob::present_len, VsnetOSS::recv(), vsnetEConnAborted(), vsnetEConnReset(), vsnetEWouldBlock(), vsnetGetLastError(), and vsnetLastError().
|
virtual |
Reimplemented from VsnetSocketBase.
Definition at line 164 of file vsnet_sockettcp.cpp.
References _sq, _sq_current, _sq_fd, _sq_mx, _sq_off, COUT, VsnetTCPSocket::SqQueues::empty(), fprintf, h, PacketMem::len(), VSMutex::lock(), VsnetTCPSocket::SqQueues::pop(), and VSMutex::unlock().
|
virtual |
Reimplemented from VsnetSocketBase.
Definition at line 131 of file vsnet_sockettcp.cpp.
References _sq, _sq_current, _sq_mx, COUT, e, VsnetTCPSocket::SqQueues::empty(), VSMutex::lock(), and VSMutex::unlock().
|
virtual |
Implements VsnetSocket.
Definition at line 151 of file vsnet_sockettcp.cpp.
|
protected |
Definition at line 123 of file vsnet_sockettcp.cpp.
References _connection_closed, VsnetSocketBase::_set, and SocketSet::waste_time().
Referenced by isActive().
Implements VsnetSocket.
Definition at line 156 of file vsnet_sockettcp.cpp.
References _sq, _sq_mx, VsnetTCPSocket::SqQueues::getLength(), VSMutex::lock(), and VSMutex::unlock().
This function copies or moves data into the given PacketMem variable. It is preferred over the other recvbuf function because it may reduce the number of copy operations by at least one.
Implements VsnetSocket.
Definition at line 270 of file vsnet_sockettcp.cpp.
References _connection_closed, _cpq, _cpq_mx, VsnetSocket::_remote_ip, VsnetSocketBase::_set, _sq_fd, VsnetSocketBase::close_fd(), Packet::copyfrom(), COUT, VSMutex::lock(), SocketSet::rem_pending(), and VSMutex::unlock().
Implements VsnetSocket.
Definition at line 104 of file vsnet_sockettcp.cpp.
References VsnetSocketBase::_set, _sq, _sq_mx, e, VsnetTCPSocket::SqQueues::empty(), Packet::getSendBufferLength(), HIPRI, VSMutex::lock(), LOPRI, VsnetTCPSocket::SqQueues::push(), VSMutex::unlock(), and SocketSet::wakeup().
|
protected |
Closed connections are noticed in isActive but evaluated by the application after recvbuf. So, we remember the situation here until the application notices it.
Definition at line 122 of file vsnet_sockettcp.h.
Referenced by isActive(), lower_selected(), private_nothread_conditional_write(), recvbuf(), and ~VsnetTCPSocket().
|
protected |
cpq = completed packet queue
Definition at line 106 of file vsnet_sockettcp.h.
Referenced by inner_complete_a_packet(), isActive(), and recvbuf().
|
protected |
Definition at line 107 of file vsnet_sockettcp.h.
Referenced by inner_complete_a_packet(), isActive(), and recvbuf().
|
protected |
Definition at line 116 of file vsnet_sockettcp.h.
Referenced by lower_selected().
|
protected |
We send sizeof(Header) bytes as a packet length indicator. Unfortunately, even these sizeof(Header) bytes may be split by TCP. These two variables are needed for collecting the sizeof(Header) bytes. Note: for the obvious reason that this happens rarely, the collection code can not be considered tested.
Definition at line 115 of file vsnet_sockettcp.h.
Referenced by lower_selected().
|
protected |
if we have received part of a TCP packet but not the complete packet, the expected length and received number of bytes are stored in _incomplete_packet. If several packets have been received at once, but the application processes them one at a time, the received, unprocessed packets are stored in the list.
Definition at line 103 of file vsnet_sockettcp.h.
Referenced by lower_selected(), and ~VsnetTCPSocket().
|
protected |
Definition at line 160 of file vsnet_sockettcp.h.
Referenced by lower_clean_sendbuf(), lower_sendbuf(), need_test_writable(), queueLen(), and sendbuf().
|
protected |
Definition at line 161 of file vsnet_sockettcp.h.
Referenced by lower_clean_sendbuf(), lower_sendbuf(), and need_test_writable().
|
protected |
Definition at line 164 of file vsnet_sockettcp.h.
Referenced by get_write_fd(), inner_complete_a_packet(), isActive(), lower_selected(), lower_sendbuf(), recvbuf(), and VsnetTCPSocket().
|
protected |
Definition at line 163 of file vsnet_sockettcp.h.
Referenced by lower_clean_sendbuf(), lower_sendbuf(), need_test_writable(), queueLen(), and sendbuf().
|
protected |
Definition at line 162 of file vsnet_sockettcp.h.
Referenced by lower_clean_sendbuf(), and lower_sendbuf().