Private Attempt to send the event to the socket. If socket no longer exists, remove it from set
10059
function sendToMultiple(send, msg, destinations, type) {
  destinations = destinations instanceof Array && destinations || [destinations];
  destinations.forEach(function(destination) {
    var set, socketIds;
    set = subscriptions[type];
    if ((socketIds = set.members(destination))) {
      return socketIds.slice(0).forEach(function(socketId) {
        if (!send.socketId(socketId, msg, destination)) {
          return set.removeFromAll(socketId);
        }
      });
    }
  });
  return true;
}
874153
function () {
    clearTimeout(timeoutId);
    var args = [];
    for (var index = 0, length = arguments.length; index < length; index++) {
      args.push(arguments[index]);
    }
    self.socketEvent = {
      namespace: action.namespace,
      eventType: action.eventType,
      args: args
    };
    callback(null, self.socketEvent);
  }
686564
public void close() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "close");
        }

        // Doing a channel.close() will actually put the keys associated with this
        // channel
        // into the associated selectors cancelledKey list, but they don't get
        // removed until the
        // next time the selector runs. In some cases, we need to make sure they are
        // really gone before we
        // we close the channel, because another thread may have requested another
        // operation
        // on the channel at the same time, which causes problems on some OS'es.
        // So, cancel them manually and wait for the selector to run once before
        // continuing

        // call super.close() to see if we are using Regular Sockets, and if so, let
        // the parent class handle closing the socket
        super.close();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "SocketChannel closing, local: " + socket.getLocalSocketAddress() + " remote: " + socket.getRemoteSocketAddress());
        }

        // synchronize on this SocketIOChannel to prevent duplicate closes from
        // being processed
        synchronized (this) {
            if (closed) {
                processClose = false;
            }
            closed = true;
        }

        if (processClose) {

            // checkCancel is only on if we need to manually cancel keys as
            // the socket close() is supposed to do that for us
            if (checkCancel) {
                // Remove socket from current selectors.
                if (channelSelectorRead != null) {
                    SelectionKey k = channelSelectorRead.getKey(channel);
                    if (k != null) {
                        CancelRequest cr = new CancelRequest(k);
                        synchronized (cr) {
                            channelSelectorRead.addCancelRequest(cr);
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "waiting for read key to be canceled, key is " + k);
                            }
                            try {
                                cr.wait();
                            } catch (InterruptedException e) {
                                // No FFDC code needed
                            }
                        } // end-sync
                    }
                }
                if (channelSelectorWrite != null) {
                    SelectionKey k = channelSelectorWrite.getKey(channel);
                    if (k != null) {
                        CancelRequest cr = new CancelRequest(k);
                        synchronized (cr) {
                            channelSelectorWrite.addCancelRequest(cr);
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "waiting for write key to be canceled, key is " + k);
                            }
                            try {
                                cr.wait();
                            } catch (InterruptedException e) {
                                // No FFDC code needed
                            }
                        } // end-sync
                    }
                }
            }

            try {
                if (channel != null) {
                    channel.close();
                }

                // need to make sure the keys get cancelled after the close call
                if (channelSelectorRead != null) {
                    channelSelectorRead.wakeup();
                    channelSelectorRead = null;
                }
                if (channelSelectorWrite != null) {
                    channelSelectorWrite.wakeup();
                    channelSelectorWrite = null;
                }

            } catch (Throwable t) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(this, tc, "Error closing channel: " + t);
                }
                // ignore all shutdown/close errors
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "close");
        }
    }
898362
def remove_reader(socket)
      if event_mask_for_socket(socket) == ZMQ::POLLIN
        remove(socket)
        return
      end
      raise ArgumentError, "not registered for readability only: %p" % socket
    end
909381
def on_close(socket, *data, &block)
      raise UnknownSocket.new(socket) unless @sockets.has_key?(socket)
      raise ArgumentError.new('Block must be supplied') unless block_given?
      raise ArgumentError.new('Block must allow at least one argument') if block.arity == 0
      if(block.arity > 0 && block.arity != (data.size + 1))
        raise ArgumentError.new('Invalid number of arguments for block')
      end
      @sockets[socket][:closed] ||= []
      @sockets[socket][:closed] << [data, block]
    end
64378
def close(self):
        

        # Close the underlying socket
        if self._sock:
            with utils.ignore_except():
                self._sock.close()
            self._sock = None

        # Purge the message buffers
        self._recvbuf = []
        self._recvbuf_partial = ''
198998
def close_socket(self):
        """"""
        if _debug: UDPDirector._debug("close_socket")

        self.socket.close()
        self.close()
        self.socket = None
1344213
def close_socket(self):
        ''''''
        log.debug("Closing socket")
        if self.sock:
            try:
                self.sock.close()
            except:
                pass

            self.sock = None
1272241
public boolean sendAndDestroy(Socket socket, int flags)
    {
        boolean ret = send(socket, flags);
        if (ret) {
            destroy();
        }
        return ret;
    }
362804
function(id, socket) {
  EventEmitter.call(this);
  this.id = id;
  this.socket = socket;

  if(!socket._socket) {
    this.remoteAddress = {
      ip: socket.address().address,
      port: socket.address().port
    };
  } else {
    this.remoteAddress = {
      ip: socket._socket.remoteAddress,
      port: socket._socket.remotePort
    };
  }

  var self = this;

  socket.once('close', this.emit.bind(this, 'disconnect'));
  socket.on('error', this.emit.bind(this, 'error'));

  socket.on('message', function(msg) {
    if(msg) {
      msg = Package.decode(msg);
      handler(self, msg);
    }
  });

  this.state = ST_INITED;

  // TODO: any other events?
}
375344
def teardown_socket(s):
  """"""
  try:
    s.shutdown(socket.SHUT_WR)
  except socket.error:
    pass
  finally:
    s.close()
347639
def _handle_socket(self, event: int, fd: int, multi: Any, data: bytes) -> None:
        
        event_map = {
            pycurl.POLL_NONE: ioloop.IOLoop.NONE,
            pycurl.POLL_IN: ioloop.IOLoop.READ,
            pycurl.POLL_OUT: ioloop.IOLoop.WRITE,
            pycurl.POLL_INOUT: ioloop.IOLoop.READ | ioloop.IOLoop.WRITE,
        }
        if event == pycurl.POLL_REMOVE:
            if fd in self._fds:
                self.io_loop.remove_handler(fd)
                del self._fds[fd]
        else:
            ioloop_event = event_map[event]
            # libcurl sometimes closes a socket and then opens a new
            # one using the same FD without giving us a POLL_NONE in
            # between.  This is a problem with the epoll IOLoop,
            # because the kernel can tell when a socket is closed and
            # removes it from the epoll automatically, causing future
            # update_handler calls to fail.  Since we can't tell when
            # this has happened, always use remove and re-add
            # instead of update.
            if fd in self._fds:
                self.io_loop.remove_handler(fd)
            self.io_loop.add_handler(fd, self._handle_events, ioloop_event)
            self._fds[fd] = ioloop_event
1308730
void onClose(AbstractSocket socket) {
		synchronized(sockets) {
			if(sockets.remove(socket.getId()) == null) throw new AssertionError("Socket not part of this context.  onClose called twice?");
		}
	}
1198847
@Override
    public void close() {
        if (closed)
            return;
        closed = true;
        tcpSocketConsumer.prepareToShutdown();

        if (shouldSendCloseMessage)

            eventLoop.addHandler(new EventHandler() {
                @Override
                public boolean action() throws InvalidEventHandlerException {
                    try {
                        TcpChannelHub.this.sendCloseMessage();
                        tcpSocketConsumer.stop();
                        closed = true;

                        if (LOG.isDebugEnabled())
                            Jvm.debug().on(getClass(), "closing connection to " + socketAddressSupplier);

                        while (clientChannel != null) {

                            if (LOG.isDebugEnabled())
                                Jvm.debug().on(getClass(), "waiting for disconnect to " + socketAddressSupplier);
                        }
                    } catch (ConnectionDroppedException e) {
                        throw new InvalidEventHandlerException(e);
                    }

                    // we just want this to run once
                    throw new InvalidEventHandlerException();
                }

                @NotNull
                @Override
                public String toString() {
                    return TcpChannelHub.class.getSimpleName() + "..close()";
                }
            });
    }
721210
function(event) {
            event = event || {code: 1000};
            _cometd._debug('WebSocket onclose', context, event, 'connecting', _connecting, 'current', _context);

            if (context.connectTimer) {
                self.clearTimeout(context.connectTimer);
            }

            self.onClose(context, event);
        }
168645
def _send(self):
        

        # Outer loop: wait for data to send
        while True:
            # Release the send lock and wait for data, then reacquire
            # the send lock
            self._send_lock.release()
            self._sendbuf_event.wait()
            self._send_lock.acquire()

            # Inner loop: send as much data as we can
            while self._sendbuf:
                sent = self._sock.send(self._sendbuf)

                # Trim that much data off the send buffer, so we don't
                # accidentally re-send anything
                self._sendbuf = self._sendbuf[sent:]

            # OK, _sendbuf is empty; clear the event so we'll sleep
            self._sendbuf_event.clear()
262648
def remove(reader)
      rc = ffi_delegate.remove(reader)
      raise_zmq_err("unable to remove socket %p" % reader) if rc == -1
      forget_socket(reader)
    end