@Override public void close() { closed = true; if (socket != null && !socket.isClosed()) { socket.close(); } }
void checkOpen() throws SocketException { if (isClosed()) { throw new SocketException("Socket is closed"); } }
/** * Close this announce connection. */ @Override protected void close() { this.stop = true; // Close the socket to force blocking operations to return. if (this.socket != null && !this.socket.isClosed()) { this.socket.close(); } }
@Override protected synchronized void implCloseSelectableChannel() throws IOException { connected = false; if (socket != null && !socket.isClosed()) { socket.close(); } else { IoBridge.closeSocket(fd); } }
private boolean isRunning() { return serverSocket != null && !serverSocket.isClosed(); }
/** * Validates that the socket is good. */ @Override public boolean validateObject(SocketAddress key, DatagramSocket socket) { return socket.isBound() && !socket.isClosed() && socket.isConnected(); } }
/** * Disconnects this UDP datagram socket from the remote host. This method * called on an unconnected socket does nothing. */ public void disconnect() { if (isClosed() || !isConnected()) { return; } impl.disconnect(); address = null; port = -1; isConnected = false; }
/** * Gets the local port which this socket is bound to. * * @return the local port of this socket or {@code -1} if this socket is * closed and {@code 0} if it is unbound. */ public int getLocalPort() { if (isClosed()) { return -1; } if (!isBound()) { return 0; } return impl.getLocalPort(); }
public void run() { final byte receive_buf[]=new byte[66000]; // to be on the safe side (IPv6 == 65575 bytes, IPv4 = 65535) final DatagramPacket packet=new DatagramPacket(receive_buf, receive_buf.length); while(thread != null && Thread.currentThread().equals(thread)) { try { // solves Android ISSUE #24748 - DatagramPacket truncated UDP in ICS if(is_android) packet.setLength(receive_buf.length); receiver_socket.receive(packet); int len=packet.getLength(); if(len > receive_buf.length && log.isErrorEnabled()) log.error(Util.getMessage("SizeOfTheReceivedPacket"), len, receive_buf.length, receive_buf.length); receive(new IpAddress(packet.getAddress(), packet.getPort()), receive_buf, packet.getOffset(), len); } catch(SocketException sock_ex) { if(receiver_socket.isClosed()) { log.debug("receiver socket is closed, exception=" + sock_ex); break; } log.error(Util.getMessage("FailedReceivingPacket"), sock_ex); } catch(Throwable ex) { log.error(Util.getMessage("FailedReceivingPacket"), ex); } } if(log.isDebugEnabled()) log.debug(name + " thread terminated"); }
@Override public synchronized void stop() throws IOException { if (socket.isClosed()) { // Allow double stop, and ignore return; } socket.close(); super.stop(); }
/** * {@inheritDoc} */ @Override public void close() { try { this.disableBatch(); } finally { if (datagramSocket != null && !datagramSocket.isClosed()) { datagramSocket.close(); } } }
@Override public void run() { final byte[] buf = new byte[MAX_PACKET_SIZE]; final DatagramPacket packet = new DatagramPacket(buf, buf.length); while (!socket.isClosed() && !Thread.currentThread().isInterrupted()) { startSignal.countDown(); try { // TODO This doesn't handle the case of a progress being split across two packets socket.receive(packet); if (packet.getLength() == 0) { continue; } final ByteArrayInputStream in = new ByteArrayInputStream(packet.getData(), packet.getOffset(), packet.getLength()); parser.processStream(in); } catch (SocketException e) { // Most likley a Socket closed exception, which we can safely ignore } catch (IOException e) { // We have no good way to report this back to the user... yet // TODO Report to the user that this failed in some way } } } }
/** * Process acknowledgments, if requested. */ @Override public void run() { try { this.ackThreadRunning = true; this.ackLatch.countDown(); DatagramPacket ackPack = new DatagramPacket(new byte[100], 100); while (true) { this.getSocket().receive(ackPack); String id = new String(ackPack.getData(), ackPack.getOffset(), ackPack.getLength()); if (logger.isDebugEnabled()) { logger.debug("Received ack for " + id + " from " + ackPack.getAddress().getHostAddress()); } CountDownLatch latch = this.ackControl.get(id); if (latch != null) { latch.countDown(); } } } catch (IOException e) { if (this.socket != null && !this.socket.isClosed()) { logger.error("Error on UDP Acknowledge thread: " + e.getMessage()); } } finally { this.ackThreadRunning = false; } }
private synchronized void setupReceiveSystem() { if (udpSocket != null && !udpSocket.isClosed() && receiveHandler != null && receiveThread == null) { setupReceiveThread(); } else if (receiveHandler == null && receiveThread != null) { receiveThread.interrupt(); receiveThread = null; if (combinedAudioExecutor != null) { combinedAudioExecutor.shutdownNow(); combinedAudioExecutor = null; } opusDecoders.valueCollection().forEach(Decoder::close); opusDecoders.clear(); } else if (receiveHandler != null && !receiveHandler.canReceiveCombined() && combinedAudioExecutor != null) { combinedAudioExecutor.shutdownNow(); combinedAudioExecutor = null; } }
if (socket != null && socket.isOpen()) //TCP keep-alive send(VoiceCode.HEARTBEAT, System.currentTimeMillis()); if (audioConnection.udpSocket != null && !audioConnection.udpSocket.isClosed()) //UDP keep-alive
long lastFrameSent = System.currentTimeMillis(); boolean sentPacket = true; while (!udpSocket.isClosed() && !sendThread.isInterrupted())
while (!udpSocket.isClosed() && !Thread.currentThread().isInterrupted())
private synchronized void setupSendSystem() { if (udpSocket != null && !udpSocket.isClosed() && sendHandler != null && sendSystem == null) { IAudioSendFactory factory = getJDA().getAudioSendFactory(); sendSystem = factory.createSendSystem(new PacketProvider()); sendSystem.setContextMap(getJDA().getContextMap()); sendSystem.start(); } else if (sendHandler == null && sendSystem != null) { sendSystem.shutdown(); sendSystem = null; if (opusEncoder != null) { Opus.INSTANCE.opus_encoder_destroy(opusEncoder); opusEncoder = null; } } }
if (_socket.isClosed()) { if (_keepRunning) { _keepRunning = false;
_log.warn("Error sending to " + packet.getPacket().getAddress(), ioe); _context.statManager().addRateData("udp.sendException", 1, packet.getLifetime()); if (_socket.isClosed()) { if (_keepRunning) { _keepRunning = false;