MCPcopy Create free account
hub / github.com/ReadyTalk/avian / Socket

Class Socket

classpath/java/net/Socket.java:18–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16import java.io.OutputStream;
17
18public class Socket implements Closeable, AutoCloseable {
19
20 private static final int SD_RECEIVE = 0x00;
21 private static final int SD_SEND = 0x01;
22 private static final int SD_BOTH = 0x02;
23
24 private static final int BUFFER_SIZE = 65535;
25
26 /**
27 * This method is called from all routines that depend on winsock in windows,
28 * so it has public visibility
29 * @throws IOException
30 */
31 public static native void init() throws IOException;
32
33 /**
34 * Creates the native socket object
35 * @return Handle to the native object
36 * @throws IOException
37 */
38 private static native /* SOCKET */long create() throws IOException;
39
40 /**
41 * Connects the native socket object to an address:port
42 * @param sock Native socket handler
43 * @param addr Address to connect to
44 * @param port Port to connect to
45 * @throws IOException
46 */
47 private static native void connect(/* SOCKET */long sock, long addr, short port) throws IOException;
48 private static native void bind(/* SOCKET */long sock, long addr, short port) throws IOException;
49
50 private static native void send(/* SOCKET */long sock, byte[] buffer, int start_pos, int count) throws IOException;
51 private static native int recv(/* SOCKET */long sock, byte[] buffer, int start_pos, int count) throws IOException;
52
53 private static native void abort(/* SOCKET */long sock);
54 private static native void close(/* SOCKET */long sock);
55 private static native void closeOutput(/* SOCKET */long sock);
56 private static native void closeInput(/* SOCKET */long sock);
57
58 private class SocketInputStream extends InputStream {
59
60 private boolean closed = false;
61
62 @Override
63 public void close() throws IOException {
64 if (!closed) {
65 closeInput(sock);
66 closed = true;
67 }
68 super.close();
69 }
70
71 @Override
72 protected void finalize() throws Throwable {
73 close();
74 super.finalize();
75 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected