libktorrent  2.2.0
socketdevice.h
1 /***************************************************************************
2  * Copyright (C) 2009 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef NET_SOCKETDEVICE_H
22 #define NET_SOCKETDEVICE_H
23 
24 #include <ktorrent_export.h>
25 #include <util/constants.h>
26 #include <net/poll.h>
27 #include <net/address.h>
28 
29 namespace net
30 {
32  {
33  public:
34  SocketDevice(bt::TransportProtocol proto);
35  virtual ~SocketDevice();
36 
37  enum State
38  {
39  IDLE,
40  CONNECTING,
41  CONNECTED,
42  BOUND,
43  CLOSED
44  };
45 
46  virtual int fd() const = 0;
47  virtual bool ok() const = 0;
48  virtual int send(const bt::Uint8* buf,int len) = 0;
49  virtual int recv(bt::Uint8* buf,int max_len) = 0;
50  virtual void close() = 0;
51  virtual void setBlocking(bool on) = 0;
52  virtual Uint32 bytesAvailable() const = 0;
53  virtual bool setTOS(unsigned char type_of_service) = 0;
54  virtual bool connectTo(const Address & addr) = 0;
56  virtual bool connectSuccesFull() = 0;
57  virtual const Address & getPeerName() const = 0;
58  virtual Address getSockName() const = 0;
59 
60 
62  bt::TransportProtocol transportProtocol() const {return transport_protocol;}
63 
68  void setRemoteAddress(const Address & a) {addr = a; remote_addr_override = true;}
69 
71  virtual void reset() = 0;
72 
73  State state() const {return m_state;}
74 
76  virtual void prepare(Poll* p,Poll::Mode mode) = 0;
77 
79  virtual bool ready(const Poll* p,Poll::Mode mode) const = 0;
80 
81  protected:
82  State m_state;
83  Address addr;
84  bool remote_addr_override;
85  bt::TransportProtocol transport_protocol;
86  };
87 
88 }
89 
90 #endif // NET_SOCKETDEVICE_H
net::SocketDevice::reset
virtual void reset()=0
reset the socket (i.e. close it and create a new one)
net::SocketDevice::connectSuccesFull
virtual bool connectSuccesFull()=0
See if a connectTo was succesfull in non blocking mode.
net::Address
Definition: address.h:41
net::SocketDevice
Definition: socketdevice.h:32
net::SocketDevice::prepare
virtual void prepare(Poll *p, Poll::Mode mode)=0
Prepare for polling.
net::SocketDevice::transportProtocol
bt::TransportProtocol transportProtocol() const
Get the used transport protocol for this SocketDevice.
Definition: socketdevice.h:62
net::SocketDevice::ready
virtual bool ready(const Poll *p, Poll::Mode mode) const =0
Check if the socket is ready according to the poll.
net::SocketDevice::setRemoteAddress
void setRemoteAddress(const Address &a)
Definition: socketdevice.h:68
net::Poll
Definition: poll.h:64