44#endif
55#include " network/bundle.hpp"
66#include " network/network_interface.hpp"
7+ #include " network/tcp_packet_receiver.hpp"
78
89namespace KBEngine {
910namespace Mercury
@@ -14,7 +15,7 @@ const int INDEXED_CHANNEL_SIZE = 512;
1415
1516
1617Channel::Channel (NetworkInterface & networkInterface,
17- const Socket * socket , Traits traits,
18+ const EndPoint * endpoint , Traits traits,
1819 PacketFilterPtr pFilter, ChannelID id):
1920 pNetworkInterface_ (&networkInterface),
2021 traits_ (traits),
@@ -38,7 +39,7 @@ Channel::Channel(NetworkInterface & networkInterface,
3839 numBytesSent_ (0 ),
3940 numBytesReceived_ (0 ),
4041 pFilter_ (pFilter),
41- pSocket_ (NULL ),
42+ pEndPoint_ (NULL ),
4243 pPacketReceiver_ (NULL )
4344{
4445 // This corresponds to the decRef in Channel::destroy.
@@ -52,45 +53,47 @@ Channel::Channel(NetworkInterface & networkInterface,
5253 }
5354
5455 this ->clearBundle ();
55- this ->socket (socket );
56+ this ->endpoint (endpoint );
5657
57- pPacketReceiver_ = new PacketReceiver (*pSocket_, networkInterface);
58+ pPacketReceiver_ = new TCPPacketReceiver (*pEndPoint_, networkInterface);
59+ pNetworkInterface_->dispatcher ().registerFileDescriptor (*pEndPoint_, pPacketReceiver_);
5860}
5961
6062// -------------------------------------------------------------------------------------
6163Channel * Channel::get (NetworkInterface & networkInterface,
62- KBESOCKET s )
64+ const Address& addr )
6365{
64- return networkInterface.findChannel (s );
66+ return networkInterface.findChannel (addr );
6567}
6668
6769// -------------------------------------------------------------------------------------
6870Channel * get (NetworkInterface & networkInterface,
69- const Socket * pSocket)
71+ const EndPoint * pSocket)
7072{
71- return networkInterface.findChannel (* pSocket);
73+ return networkInterface.findChannel (pSocket-> addr () );
7274}
7375
7476// -------------------------------------------------------------------------------------
75- void Channel::socket (const Socket* socket )
77+ void Channel::endpoint (const EndPoint* endpoint )
7678{
77- if (socket && pSocket_ != socket )
79+ if (endpoint && pEndPoint_ != endpoint )
7880 {
7981 lastReceivedTime_ = timestamp ();
80- pSocket_ = const_cast <Socket *>(socket );
82+ pEndPoint_ = const_cast <EndPoint *>(endpoint );
8183 }
8284}
8385
8486// -------------------------------------------------------------------------------------
8587Channel::~Channel ()
8688{
8789 pNetworkInterface_->onChannelGone (this );
88- pSocket_->close ();
89- pSocket_->detach ();
90+ pNetworkInterface_->dispatcher ().deregisterFileDescriptor (*pEndPoint_);
91+ pEndPoint_->close ();
92+ pEndPoint_->detach ();
9093
9194 SAFE_RELEASE (pPacketReceiver_);
9295 SAFE_RELEASE (pBundle_);
93- SAFE_RELEASE (pSocket_ );
96+ SAFE_RELEASE (pEndPoint_ );
9497}
9598
9699// -------------------------------------------------------------------------------------
@@ -161,7 +164,7 @@ const char * Channel::c_str() const
161164{
162165 static char dodgyString[ 40 ];
163166
164- int length = pSocket_ ->addr ().writeToString (dodgyString, sizeof (dodgyString));
167+ int length = pEndPoint_ ->addr ().writeToString (dodgyString, sizeof (dodgyString));
165168
166169 length += kbe_snprintf (dodgyString + length,
167170 sizeof (dodgyString) - length, " /%d" , id_);
@@ -216,17 +219,17 @@ void Channel::handleTimeout(TimerHandle, void * arg)
216219}
217220
218221// -------------------------------------------------------------------------------------
219- void Channel::reset (const Socket* socket , bool warnOnDiscard)
222+ void Channel::reset (const EndPoint* endpoint , bool warnOnDiscard)
220223{
221224 // Don't do anything if the address hasn't changed.
222- if (socket == pSocket_ )
225+ if (endpoint == pEndPoint_ )
223226 {
224227 return ;
225228 }
226229
227230 // This handles registering this channel (deregistering done in
228231 // clearState above).
229- this ->socket (socket );
232+ this ->endpoint (endpoint );
230233
231234 // If we're establishing this channel, call the bundle primer, since
232235 // we just cleared the bundle.
0 commit comments