X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsocket.cpp;h=7a82463bcd16609a89bd69bf816aece68ab66b3a;hb=5cf15ce8f6b17a47f662eb8f60de619fd6bf7b53;hp=7bccec6de1303997f07883898ea947b99fd12ba4;hpb=bc7f7210f6963c7bd23cce9cea3d3e82a2968f98;p=libs%2Fnet.git diff --git a/source/socket.cpp b/source/socket.cpp index 7bccec6..7a82463 100644 --- a/source/socket.cpp +++ b/source/socket.cpp @@ -1,5 +1,5 @@ #ifndef WIN32 -#include +#include #include #include #endif @@ -108,8 +108,6 @@ const IO::Handle &Socket::get_event_handle() void Socket::bind(const SockAddr &addr) { - check_state(false); - sockaddr_storage sa; unsigned size = addr.fill_sockaddr(sa); @@ -148,12 +146,6 @@ const SockAddr &Socket::get_peer_address() const return *peer_addr; } -void Socket::check_state(bool conn) const -{ - if(conn && !connected) - throw bad_socket_state("not connected"); -} - int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) { #ifdef WIN32 @@ -174,7 +166,8 @@ int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) unsigned Socket::do_write(const char *buf, unsigned size) { - check_state(true); + if(!connected) + throw bad_socket_state("not connected"); if(size==0) return 0; @@ -193,7 +186,9 @@ unsigned Socket::do_write(const char *buf, unsigned size) unsigned Socket::do_read(char *buf, unsigned size) { - check_state(true); + if(!connected) + throw bad_socket_state("not connected"); + if(size==0) return 0;