53 UdpSocket::UdpSocket()
56 memset(&this->udp_read_buffer_, 0,
sizeof(this->udp_read_buffer_));
57 udp_read_head_ = this->udp_read_buffer_;
61 UdpSocket::~UdpSocket()
65 CLOSE(this->getSockHandle());
68 int UdpSocket::rawSendBytes(
char *buffer,
shared_int num_bytes)
70 int rc = this->SOCKET_FAIL;
72 rc = SEND_TO(this->getSockHandle(), buffer,
73 num_bytes, 0, (sockaddr *)&this->sockaddr_,
74 sizeof(this->sockaddr_));
79 int UdpSocket::rawReceiveBytes(
char *buffer,
shared_int num_bytes)
84 if(udp_read_len_ == 0) {
86 addrSize =
sizeof(this->sockaddr_);
88 rc = RECV_FROM(this->getSockHandle(), &this->udp_read_buffer_[0], this->MAX_BUFFER_SIZE,
89 0, (sockaddr *)&this->sockaddr_, &addrSize);
92 udp_read_head_ = this->udp_read_buffer_;
95 if(num_bytes == 0 || num_bytes >= udp_read_len_)
96 len_cpy = udp_read_len_;
99 memcpy(buffer, udp_read_head_, len_cpy);
100 udp_read_head_ += len_cpy;
101 udp_read_len_ -= len_cpy;
105 bool UdpSocket::rawPoll(
int timeout,
bool & ready,
bool & error)
107 if(udp_read_len_ > 0) {
115 fd_set read, write, except;
116 int rc = this->SOCKET_FAIL;
122 time.tv_sec = timeout / 1000;
123 time.tv_usec = (timeout % 1000) * 1000;
129 FD_SET(this->getSockHandle(), &read);
130 FD_SET(this->getSockHandle(), &except);
132 rc = SELECT(this->getSockHandle() + 1, &read, &write, &except, &time);
134 if (this->SOCKET_FAIL != rc) {
138 if (FD_ISSET(this->getSockHandle(), &read)) {
142 else if(FD_ISSET(this->getSockHandle(), &except)) {
147 LOG_WARN(
"Select returned, but no flags are set");
152 this->logSocketError(
"Socket select function failed", rc, errno);
Contains platform specific type definitions that guarantee the size of primitive data types...
#define LOG_WARN(format,...)