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