int DatagramSocket::connect(const SockAddr &addr)
{
- check_state(false);
-
sockaddr_storage sa;
socklen_t size = addr.fill_sockaddr(sa);
unsigned DatagramSocket::sendto(const char *buf, unsigned size, const SockAddr &addr_)
{
- check_state(false);
-
if(size==0)
return 0;
unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&addr_)
{
- check_state(false);
-
if(size==0)
return 0;
void Socket::bind(const SockAddr &addr)
{
- check_state(false);
-
sockaddr_storage sa;
unsigned size = addr.fill_sockaddr(sa);
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
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;
unsigned Socket::do_read(char *buf, unsigned size)
{
- check_state(true);
+ if(!connected)
+ throw bad_socket_state("not connected");
+
if(size==0)
return 0;
const SockAddr &get_local_address() const;
const SockAddr &get_peer_address() const;
protected:
- void check_state(bool) const;
int set_option(int, int, const void *, socklen_t);
int get_option(int, int, void *, socklen_t *) const;
unsigned do_write(const char *, unsigned);
int StreamSocket::poll_connect(const Time::TimeDelta &timeout)
{
- check_state(false);
if(!connecting)
throw bad_socket_state("not connecting");
int StreamSocket::connect(const SockAddr &addr)
{
- check_state(false);
-
if(connected)
throw bad_socket_state("already connected");