void Socket::connect(const Addr& addr) { int err = ::connect(m_socket, (const struct sockaddr *)&(addr.getAddr()), sizeof (addr.getAddr())); if(err < 0) throw ConnectErr(errno); m_connected = true; }
int Socket::send(const char* msg, size_t len, const Addr& dest, int flags, CheckingType check) { if(check == DONT_CHECK) { return ::sendto(m_socket, msg, len, flags, (struct sockaddr *)&(dest.getAddr()), sizeof (dest.getAddr())); } else { for(;;) { int sent = ::sendto(m_socket, msg, len, flags, (struct sockaddr *)&(dest.getAddr()), sizeof (dest.getAddr())); if(sent != -1 || (errno != EINTR && errno != EWOULDBLOCK)) return sent; } } }
int Socket::send( const char* msg, size_t len, const Addr& dest, int flags, CheckingType check ) { if( check == DONT_CHECK ) { return ::sendto( getFD(), msg, #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) (int)len, #else len, #endif flags, (struct sockaddr *)&( dest.getAddr() ), sizeof( dest.getAddr() ) ); } else { for(;;) { int sent = ::sendto( getFD(), msg, #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) (int)len, #else len, #endif flags, (struct sockaddr *)&( dest.getAddr() ), sizeof( dest.getAddr() ) ); if( sent != -1 || ( errno != EINTR #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) && errno != WSAEWOULDBLOCK #else && errno != EWOULDBLOCK #endif ) ) return sent; } } }
bool Socket::bind( const Addr& addr ) { if( isOpen() ) { int err = ::bind( getFD(), (struct sockaddr *)&( addr.getAddr() ), sizeof( addr.getAddr() ) ); #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) if( err == SOCKET_ERROR ) return false; #else if( err < 0 ) return false; #endif return true; } return false; }
int SocketDgram::sharedOpen(const Addr& local, int protocolFamily) { bool error = false; if(local == Addr::sapAny) { if(protocolFamily == PF_INET) { if(bindport(this->getHandle(), INADDR_ANY, protocolFamily) == -1) error = true; } } else if(OS::bind(this->getHandle(), reinterpret_cast<sockaddr*> (local.getAddr()), local.getSize()) == -1) error = true; if(error) this->close(); return error ? -1:0; }
void Socket::bind(const Addr& addr) { int err = ::bind(m_socket, (struct sockaddr *)&(addr.getAddr()), sizeof (addr.getAddr())); if(err < 0) throw BindErr(errno); }