lots of new files
[IRC.git] / Robust / src / ClassLibrary / Socket.java
1 public class Socket {
2     /* Data pending flag */
3     external flag IOPending;    
4     /* File Descriptor */
5     int fd;
6     private SocketInputStream sin;
7     
8     public Socket() {
9         sin=new SocketInputStream(this);
10
11     }
12
13     public InputStream getInputStream() {
14         return sin;
15     }
16
17     public Socket(String host, int port) {
18         InetAddress address=InetAddress.getByName(host);
19         fd=nativeBind(address.getAddress(), port);
20         nativeConnect(fd, address.getAddress(), port);
21     }
22     
23     public Socket(InetAddress address, int port) {
24         fd=nativeBind(address.getAddress(), port);
25         nativeConnect(fd, address.getAddress(), port);
26     }
27
28     public static native int nativeBind(byte[] address, int port);
29
30     public native int nativeConnect(int fd, byte[] address, int port);
31     
32     int setFD(int filed) {
33         fd=filed;
34     }
35
36     public int read(byte[] b) {
37         return nativeRead(b);
38     }
39     public void write(byte[] b) {
40         nativeWrite(b);
41     }
42
43     private native int nativeRead(byte[] b);
44     private native void nativeWrite(byte[] b);
45     private native void nativeClose();
46
47     public void close() {
48         nativeClose();
49     }
50 }