]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/inspsocket.cpp
24f9af3a234de00856f37497d4466e4a39473679
[user/henk/code/inspircd.git] / src / inspsocket.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Core: libIRCDinspsocket */
15
16 #include "socket.h"
17 #include "inspstring.h"
18 #include "socketengine.h"
19 #include "inspircd.h"
20
21 using irc::sockets::OpenTCPSocket;
22
23 bool BufferedSocket::Readable()
24 {
25         return ((this->state != I_CONNECTING) && (this->WaitingForWriteEvent == false));
26 }
27
28 BufferedSocket::BufferedSocket(InspIRCd* SI)
29 {
30         this->Timeout = NULL;
31         this->state = I_DISCONNECTED;
32         this->fd = -1;
33         this->WaitingForWriteEvent = false;
34         this->Instance = SI;
35         this->IsIOHooked = false;
36 }
37
38 BufferedSocket::BufferedSocket(InspIRCd* SI, int newfd, const char* ip)
39 {
40         this->Timeout = NULL;
41         this->fd = newfd;
42         this->state = I_CONNECTED;
43         strlcpy(this->IP,ip,MAXBUF);
44         this->WaitingForWriteEvent = false;
45         this->Instance = SI;
46         this->IsIOHooked = false;
47         if (this->fd > -1)
48                 this->Instance->SE->AddFd(this);
49 }
50
51 BufferedSocket::BufferedSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool listening, unsigned long maxtime, const std::string &connectbindip)
52 {
53         this->cbindip = connectbindip;
54         this->fd = -1;
55         this->Instance = SI;
56         strlcpy(host,ipaddr.c_str(),MAXBUF);
57         this->WaitingForWriteEvent = false;
58         this->IsIOHooked = false;
59         this->Timeout = NULL;
60         if (listening)
61         {
62                 if ((this->fd = OpenTCPSocket(host)) == ERROR)
63                 {
64                         this->fd = -1;
65                         this->state = I_ERROR;
66                         this->OnError(I_ERR_SOCKET);
67                         return;
68                 }
69                 else
70                 {
71                         if (!SI->BindSocket(this->fd,aport,(char*)ipaddr.c_str()))
72                         {
73                                 this->Close();
74                                 this->fd = -1;
75                                 this->state = I_ERROR;
76                                 this->OnError(I_ERR_BIND);
77                                 this->ClosePending = true;
78                                 return;
79                         }
80                         else
81                         {
82                                 this->state = I_LISTENING;
83                                 this->port = aport;
84                                 if (this->fd > -1)
85                                 {
86                                         if (!this->Instance->SE->AddFd(this))
87                                         {
88                                                 this->Close();
89                                                 this->state = I_ERROR;
90                                                 this->OnError(I_ERR_NOMOREFDS);
91                                         }
92                                 }
93                                 return;
94                         }
95                 }
96         }
97         else
98         {
99                 strlcpy(this->host,ipaddr.c_str(),MAXBUF);
100                 this->port = aport;
101
102                 bool ipvalid = true;
103 #ifdef IPV6
104                 if (strchr(host,':'))
105                 {
106                         in6_addr n;
107                         if (inet_pton(AF_INET6, host, &n) < 1)
108                                 ipvalid = false;
109                 }
110                 else
111 #endif
112                 {
113                         in_addr n;
114                         if (inet_aton(host,&n) < 1)
115                                 ipvalid = false;
116                 }
117                 if (!ipvalid)
118                 {
119                         this->Instance->Log(DEBUG,"BUG: Hostname passed to BufferedSocket, rather than an IP address!");
120                         this->OnError(I_ERR_CONNECT);
121                         this->Close();
122                         this->fd = -1;
123                         this->state = I_ERROR;
124                         return;
125                 }
126                 else
127                 {
128                         strlcpy(this->IP,host,MAXBUF);
129                         timeout_val = maxtime;
130                         if (!this->DoConnect())
131                         {
132                                 this->OnError(I_ERR_CONNECT);
133                                 this->Close();
134                                 this->fd = -1;
135                                 this->state = I_ERROR;
136                                 return;
137                         }
138                 }
139         }
140 }
141
142 void BufferedSocket::WantWrite()
143 {
144         this->Instance->SE->WantWrite(this);
145         this->WaitingForWriteEvent = true;
146 }
147
148 void BufferedSocket::SetQueues(int nfd)
149 {
150         // attempt to increase socket sendq and recvq as high as its possible
151         int sendbuf = 32768;
152         int recvbuf = 32768;
153         if(setsockopt(nfd,SOL_SOCKET,SO_SNDBUF,(const char *)&sendbuf,sizeof(sendbuf)) || setsockopt(nfd,SOL_SOCKET,SO_RCVBUF,(const char *)&recvbuf,sizeof(sendbuf)))
154         {
155                 //this->Instance->Log(DEFAULT, "Could not increase SO_SNDBUF/SO_RCVBUF for socket %u", GetFd());
156                 ; // do nothing. I'm a little sick of people trying to interpret this message as a result of why their incorrect setups don't work.
157         }
158 }
159
160 /* Most irc servers require you to specify the ip you want to bind to.
161  * If you dont specify an IP, they rather dumbly bind to the first IP
162  * of the box (e.g. INADDR_ANY). In InspIRCd, we scan thought the IP
163  * addresses we've bound server ports to, and we try and bind our outbound
164  * connections to the first usable non-loopback and non-any IP we find.
165  * This is easier to configure when you have a lot of links and a lot
166  * of servers to configure.
167  */
168 bool BufferedSocket::BindAddr(const std::string &ip)
169 {
170         ConfigReader Conf(this->Instance);
171         socklen_t size = sizeof(sockaddr_in);
172 #ifdef IPV6
173         bool v6 = false;
174         /* Are we looking for a binding to fit an ipv6 host? */
175         if ((ip.empty()) || (ip.find(':') != std::string::npos))
176                 v6 = true;
177 #endif
178         int j = 0;
179         while (j < Conf.Enumerate("bind") || (!ip.empty()))
180         {
181                 std::string IP = ip.empty() ? Conf.ReadValue("bind","address",j) : ip;
182                 if (!ip.empty() || Conf.ReadValue("bind","type",j) == "servers")
183                 {
184                         if (!ip.empty() || ((IP != "*") && (IP != "127.0.0.1") && (!IP.empty()) && (IP != "::1")))
185                         {
186                                 /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
187                                 sockaddr* s = new sockaddr[2];
188 #ifdef IPV6
189                                 if (v6)
190                                 {
191                                         in6_addr n;
192                                         if (inet_pton(AF_INET6, IP.c_str(), &n) > 0)
193                                         {
194                                                 memcpy(&((sockaddr_in6*)s)->sin6_addr, &n, sizeof(sockaddr_in6));
195                                                 ((sockaddr_in6*)s)->sin6_port = 0;
196                                                 ((sockaddr_in6*)s)->sin6_family = AF_INET6;
197                                                 size = sizeof(sockaddr_in6);
198                                         }
199                                         else
200                                         {
201                                                 delete[] s;
202                                                 j++;
203                                                 continue;
204                                         }
205                                 }
206                                 else
207 #endif
208                                 {
209                                         in_addr n;
210                                         if (inet_aton(IP.c_str(), &n) > 0)
211                                         {
212                                                 ((sockaddr_in*)s)->sin_addr = n;
213                                                 ((sockaddr_in*)s)->sin_port = 0;
214                                                 ((sockaddr_in*)s)->sin_family = AF_INET;
215                                         }
216                                         else
217                                         {
218                                                 delete[] s;
219                                                 j++;
220                                                 continue;
221                                         }
222                                 }
223
224                                 if (Instance->SE->Bind(this->fd, s, size) < 0)
225                                 {
226                                         this->state = I_ERROR;
227                                         this->OnError(I_ERR_BIND);
228                                         this->fd = -1;
229                                         delete[] s;
230                                         return false;
231                                 }
232
233                                 delete[] s;
234                                 return true;
235                         }
236                 }
237                 j++;
238         }
239         return true;
240 }
241
242 bool BufferedSocket::DoConnect()
243 {
244         /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
245         sockaddr* addr = new sockaddr[2];
246         socklen_t size = sizeof(sockaddr_in);
247 #ifdef IPV6
248         bool v6 = false;
249         if ((!*this->host) || strchr(this->host, ':'))
250                 v6 = true;
251
252         if (v6)
253         {
254                 this->fd = socket(AF_INET6, SOCK_STREAM, 0);
255                 if ((this->fd > -1) && ((strstr(this->IP,"::ffff:") != (char*)&this->IP) && (strstr(this->IP,"::FFFF:") != (char*)&this->IP)))
256                 {
257                         if (!this->BindAddr(this->cbindip))
258                         {
259                                 delete[] addr;
260                                 return false;
261                         }
262                 }
263         }
264         else
265 #endif
266         {
267                 this->fd = socket(AF_INET, SOCK_STREAM, 0);
268                 if (this->fd > -1)
269                 {
270                         if (!this->BindAddr(this->cbindip))
271                         {
272                                 delete[] addr;
273                                 return false;
274                         }
275                 }
276         }
277
278         if (this->fd == -1)
279         {
280                 this->state = I_ERROR;
281                 this->OnError(I_ERR_SOCKET);
282                 delete[] addr;
283                 return false;
284         }
285
286 #ifdef IPV6
287         if (v6)
288         {
289                 in6_addr addy;
290                 if (inet_pton(AF_INET6, this->host, &addy) > 0)
291                 {
292                         ((sockaddr_in6*)addr)->sin6_family = AF_INET6;
293                         memcpy(&((sockaddr_in6*)addr)->sin6_addr, &addy, sizeof(addy));
294                         ((sockaddr_in6*)addr)->sin6_port = htons(this->port);
295                         size = sizeof(sockaddr_in6);
296                 }
297         }
298         else
299 #endif
300         {
301                 in_addr addy;
302                 if (inet_aton(this->host, &addy) > 0)
303                 {
304                         ((sockaddr_in*)addr)->sin_family = AF_INET;
305                         ((sockaddr_in*)addr)->sin_addr = addy;
306                         ((sockaddr_in*)addr)->sin_port = htons(this->port);
307                 }
308         }
309
310         Instance->SE->NonBlocking(this->fd);
311
312 #ifdef WIN32
313         /* UGH for the LOVE OF ZOMBIE JESUS SOMEONE FIX THIS!!!!!!!!!!! */
314         Instance->SE->Blocking(this->fd);
315 #endif
316
317         if (Instance->SE->Connect(this, (sockaddr*)addr, size) == -1)
318         {
319                 if (errno != EINPROGRESS)
320                 {
321                         this->OnError(I_ERR_CONNECT);
322                         this->Close();
323                         this->state = I_ERROR;
324                         return false;
325                 }
326
327                 this->Timeout = new SocketTimeout(this->GetFd(), this->Instance, this, timeout_val, this->Instance->Time());
328                 this->Instance->Timers->AddTimer(this->Timeout);
329         }
330 #ifdef WIN32
331         /* CRAQ SMOKING STUFF TO BE FIXED */
332         Instance->SE->NonBlocking(this->fd);
333 #endif
334         this->state = I_CONNECTING;
335         if (this->fd > -1)
336         {
337                 if (!this->Instance->SE->AddFd(this))
338                 {
339                         this->OnError(I_ERR_NOMOREFDS);
340                         this->Close();
341                         this->state = I_ERROR;
342                         return false;
343                 }
344                 this->SetQueues(this->fd);
345         }
346
347         Instance->Log(DEBUG,"BufferedSocket::DoConnect success");
348         return true;
349 }
350
351
352 void BufferedSocket::Close()
353 {
354         /* Save this, so we dont lose it,
355          * otherise on failure, error messages
356          * might be inaccurate.
357          */
358         int save = errno;
359         if (this->fd > -1)
360         {
361                 if (this->IsIOHooked && Instance->Config->GetIOHook(this))
362                 {
363                         try
364                         {
365                                 Instance->Config->GetIOHook(this)->OnRawSocketClose(this->fd);
366                         }
367                         catch (CoreException& modexcept)
368                         {
369                                 Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
370                         }
371                 }
372                 Instance->SE->Shutdown(this, 2);
373                 if (Instance->SE->Close(this) != -1)
374                         this->OnClose();
375
376                 if (Instance->SocketCull.find(this) == Instance->SocketCull.end())
377                         Instance->SocketCull[this] = this;
378         }
379         errno = save;
380 }
381
382 std::string BufferedSocket::GetIP()
383 {
384         return this->IP;
385 }
386
387 char* BufferedSocket::Read()
388 {
389         if (!Instance->SE->BoundsCheckFd(this))
390                 return NULL;
391
392         int n = 0;
393
394         if (this->IsIOHooked)
395         {
396                 int result2 = 0;
397                 int MOD_RESULT = 0;
398                 try
399                 {
400                         MOD_RESULT = Instance->Config->GetIOHook(this)->OnRawSocketRead(this->fd,this->ibuf,sizeof(this->ibuf),result2);
401                 }
402                 catch (CoreException& modexcept)
403                 {
404                         Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
405                 }
406                 if (MOD_RESULT < 0)
407                 {
408                         n = -1;
409                         errno = EAGAIN;
410                 }
411                 else
412                 {
413                         n = result2;
414                 }
415         }
416         else
417         {
418                 n = recv(this->fd,this->ibuf,sizeof(this->ibuf),0);
419         }
420
421         if ((n > 0) && (n <= (int)sizeof(this->ibuf)))
422         {
423                 ibuf[n] = 0;
424                 return ibuf;
425         }
426         else
427         {
428                 int err = errno;
429                 if (err == EAGAIN)
430                         return "";
431                 else
432                         return NULL;
433         }
434 }
435
436 void BufferedSocket::MarkAsClosed()
437 {
438 }
439
440 // There are two possible outcomes to this function.
441 // It will either write all of the data, or an undefined amount.
442 // If an undefined amount is written the connection has failed
443 // and should be aborted.
444 int BufferedSocket::Write(const std::string &data)
445 {
446         /* Try and append the data to the back of the queue, and send it on its way
447          */
448         outbuffer.push_back(data);
449         this->Instance->SE->WantWrite(this);
450         return (!this->FlushWriteBuffer());
451 }
452
453 bool BufferedSocket::FlushWriteBuffer()
454 {
455         errno = 0;
456         if ((this->fd > -1) && (this->state == I_CONNECTED))
457         {
458                 if (this->IsIOHooked)
459                 {
460                         while (outbuffer.size() && (errno != EAGAIN))
461                         {
462                                 try
463                                 {
464                                         /* XXX: The lack of buffering here is NOT a bug, modules implementing this interface have to
465                                          * implement their own buffering mechanisms
466                                          */
467                                         Instance->Config->GetIOHook(this)->OnRawSocketWrite(this->fd, outbuffer[0].c_str(), outbuffer[0].length());
468                                         outbuffer.pop_front();
469                                 }
470                                 catch (CoreException& modexcept)
471                                 {
472                                         Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
473                                         return true;
474                                 }
475                         }
476                 }
477                 else
478                 {
479                         /* If we have multiple lines, try to send them all,
480                          * not just the first one -- Brain
481                          */
482                         while (outbuffer.size() && (errno != EAGAIN))
483                         {
484                                 /* Send a line */
485                                 int result = Instance->SE->Send(this, outbuffer[0].c_str(), outbuffer[0].length(), 0);
486
487                                 if (result > 0)
488                                 {
489                                         if ((unsigned int)result >= outbuffer[0].length())
490                                         {
491                                                 /* The whole block was written (usually a line)
492                                                  * Pop the block off the front of the queue,
493                                                  * dont set errno, because we are clear of errors
494                                                  * and want to try and write the next block too.
495                                                  */
496                                                 outbuffer.pop_front();
497                                         }
498                                         else
499                                         {
500                                                 std::string temp = outbuffer[0].substr(result);
501                                                 outbuffer[0] = temp;
502                                                 /* We didnt get the whole line out. arses.
503                                                  * Try again next time, i guess. Set errno,
504                                                  * because we shouldnt be writing any more now,
505                                                  * until the socketengine says its safe to do so.
506                                                  */
507                                                 errno = EAGAIN;
508                                         }
509                                 }
510                                 else if (result == 0)
511                                 {
512                                         this->Instance->SE->DelFd(this);
513                                         this->Close();
514                                         return true;
515                                 }
516                                 else if ((result == -1) && (errno != EAGAIN))
517                                 {
518                                         this->OnError(I_ERR_WRITE);
519                                         this->state = I_ERROR;
520                                         this->Instance->SE->DelFd(this);
521                                         this->Close();
522                                         return true;
523                                 }
524                         }
525                 }
526         }
527
528         if ((errno == EAGAIN) && (fd > -1))
529         {
530                 this->Instance->SE->WantWrite(this);
531         }
532
533         return (fd < 0);
534 }
535
536 void SocketTimeout::Tick(time_t)
537 {
538         if (ServerInstance->SE->GetRef(this->sfd) != this->sock)
539                 return;
540
541         if (this->sock->state == I_CONNECTING)
542         {
543                 // for non-listening sockets, the timeout can occur
544                 // which causes termination of the connection after
545                 // the given number of seconds without a successful
546                 // connection.
547                 this->sock->OnTimeout();
548                 this->sock->OnError(I_ERR_TIMEOUT);
549                 this->sock->timeout = true;
550
551                 /* NOTE: We must set this AFTER DelFd, as we added
552                  * this socket whilst writeable. This means that we
553                  * must DELETE the socket whilst writeable too!
554                  */
555                 this->sock->state = I_ERROR;
556
557                 if (ServerInstance->SocketCull.find(this->sock) == ServerInstance->SocketCull.end())
558                         ServerInstance->SocketCull[this->sock] = this->sock;
559         }
560
561         this->sock->Timeout = NULL;
562 }
563
564 bool BufferedSocket::Poll()
565 {
566         int incoming = -1;
567
568 #ifndef WINDOWS
569         if (!Instance->SE->BoundsCheckFd(this))
570                 return false;
571 #endif
572
573         if (Instance->SE->GetRef(this->fd) != this)
574                 return false;
575
576         switch (this->state)
577         {
578                 case I_CONNECTING:
579                         /* Our socket was in write-state, so delete it and re-add it
580                          * in read-state.
581                          */
582 #ifndef WINDOWS
583                         if (this->fd > -1)
584                         {
585                                 this->Instance->SE->DelFd(this);
586                                 if (!this->Instance->SE->AddFd(this))
587                                         return false;
588                         }
589 #endif
590                         this->SetState(I_CONNECTED);
591
592                         if (Instance->Config->GetIOHook(this))
593                         {
594                                 Instance->Log(DEBUG,"Hook for raw connect");
595                                 try
596                                 {
597                                         Instance->Config->GetIOHook(this)->OnRawSocketConnect(this->fd);
598                                 }
599                                 catch (CoreException& modexcept)
600                                 {
601                                         Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
602                                 }
603                         }
604                         return this->OnConnected();
605                 break;
606                 case I_LISTENING:
607                 {
608                         /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
609                         sockaddr* client = new sockaddr[2];
610                         length = sizeof (sockaddr_in);
611                         std::string recvip;
612 #ifdef IPV6
613                         if ((!*this->host) || strchr(this->host, ':'))
614                                 length = sizeof(sockaddr_in6);
615 #endif
616                         incoming = Instance->SE->Accept(this, client, &length);
617 #ifdef IPV6
618                         if ((!*this->host) || strchr(this->host, ':'))
619                         {
620                                 char buf[1024];
621                                 recvip = inet_ntop(AF_INET6, &((sockaddr_in6*)client)->sin6_addr, buf, sizeof(buf));
622                         }
623                         else
624 #endif
625                         Instance->SE->NonBlocking(incoming);
626
627                         recvip = inet_ntoa(((sockaddr_in*)client)->sin_addr);
628                         this->OnIncomingConnection(incoming, (char*)recvip.c_str());
629
630                         if (this->IsIOHooked)
631                         {
632                                 try
633                                 {
634                                         Instance->Config->GetIOHook(this)->OnRawSocketAccept(incoming, recvip.c_str(), this->port);
635                                 }
636                                 catch (CoreException& modexcept)
637                                 {
638                                         Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
639                                 }
640                         }
641
642                         this->SetQueues(incoming);
643
644                         delete[] client;
645                         return true;
646                 }
647                 break;
648                 case I_CONNECTED:
649                         /* Process the read event */
650                         return this->OnDataReady();
651                 break;
652                 default:
653                 break;
654         }
655         return true;
656 }
657
658 void BufferedSocket::SetState(BufferedSocketState s)
659 {
660         this->state = s;
661 }
662
663 BufferedSocketState BufferedSocket::GetState()
664 {
665         return this->state;
666 }
667
668 int BufferedSocket::GetFd()
669 {
670         return this->fd;
671 }
672
673 bool BufferedSocket::OnConnected() { return true; }
674 void BufferedSocket::OnError(BufferedSocketError) { return; }
675 int BufferedSocket::OnDisconnect() { return 0; }
676 int BufferedSocket::OnIncomingConnection(int, char*) { return 0; }
677 bool BufferedSocket::OnDataReady() { return true; }
678 bool BufferedSocket::OnWriteReady() { return true; }
679 void BufferedSocket::OnTimeout() { return; }
680 void BufferedSocket::OnClose() { return; }
681
682 BufferedSocket::~BufferedSocket()
683 {
684         this->Close();
685         if (Timeout)
686         {
687                 Instance->Timers->DelTimer(Timeout);
688                 Timeout = NULL;
689         }
690 }
691
692 void BufferedSocket::HandleEvent(EventType et, int errornum)
693 {
694         switch (et)
695         {
696                 case EVENT_ERROR:
697                         switch (errornum)
698                         {
699                                 case ETIMEDOUT:
700                                         this->OnError(I_ERR_TIMEOUT);
701                                 break;
702                                 case ECONNREFUSED:
703                                 case 0:
704                                         this->OnError(this->state == I_CONNECTING ? I_ERR_CONNECT : I_ERR_WRITE);
705                                 break;
706                                 case EADDRINUSE:
707                                         this->OnError(I_ERR_BIND);
708                                 break;
709                                 case EPIPE:
710                                 case EIO:
711                                         this->OnError(I_ERR_WRITE);
712                                 break;
713                         }
714                         if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
715                                 this->Instance->SocketCull[this] = this;
716                         return;
717                 break;
718                 case EVENT_READ:
719                         if (!this->Poll())
720                         {
721                                 if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
722                                         this->Instance->SocketCull[this] = this;
723                                 return;
724                         }
725                 break;
726                 case EVENT_WRITE:
727                         if (this->WaitingForWriteEvent)
728                         {
729                                 this->WaitingForWriteEvent = false;
730                                 if (!this->OnWriteReady())
731                                 {
732                                         if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
733                                                 this->Instance->SocketCull[this] = this;
734                                         return;
735                                 }
736                         }
737                         if (this->state == I_CONNECTING)
738                         {
739                                 /* This might look wrong as if we should be actually calling
740                                  * with EVENT_WRITE, but trust me it is correct. There are some
741                                  * writeability-state things in the read code, because of how
742                                  * BufferedSocket used to work regarding write buffering in previous
743                                  * versions of InspIRCd. - Brain
744                                  */
745                                 this->HandleEvent(EVENT_READ);
746                                 return;
747                         }
748                         else
749                         {
750                                 if (this->FlushWriteBuffer())
751                                 {
752                                         if (this->Instance->SocketCull.find(this) == this->Instance->SocketCull.end())
753                                                 this->Instance->SocketCull[this] = this;
754                                         return;
755                                 }
756                         }
757                 break;
758         }
759 }
760