-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseSocketImpl.java
executable file
·143 lines (116 loc) · 4.19 KB
/
BaseSocketImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import java.net.*;
import java.io.*;
abstract class BaseSocketImpl extends SocketImpl {
// SocketImpl data members:
// protected InetAddress address;
// protected int port;
// protected int localport;
/**
* Creates either a stream or a datagram socket.
*
* @param stream if <code>true</code>, create a stream socket;
* otherwise, create a datagram socket.
* @exception IOException if an I/O error occurs while creating the
* socket.
*/
protected void create(boolean stream) throws IOException {
if(!stream)
throw new IOException("Datagram socket not implemented!");
}
/**
* Connects this socket to the specified port on the named host.
*
* @param host the name of the remote host.
* @param port the port number.
* @exception IOException if an I/O error occurs when connecting to the
* remote host.
*/
protected void connect(String host, int port) throws IOException {
connect(InetAddress.getByName(host), port);
}
/**
* Connects this socket to the specified port on the named host.
* This method connects, but does not implement the timeout.
*
* @param address IP and port to connect to
* @param timeout thrown away
* @exception IOException if an I/O error occurs when connecting to the
* remote host.
*/
protected void connect(SocketAddress address,
int timeout) throws IOException {
connect(((InetSocketAddress)address).getAddress(),
((InetSocketAddress)address).getPort());
}
/**
* Binds this socket to the specified port number on the specified host.
*
* @param host the IP address of the remote host.
* @param port the port number.
* @exception IOException if an I/O error occurs when binding this socket.
*/
protected void bind(InetAddress host, int port) throws IOException {
localport = port;
}
/**
* Sets the maximum queue length for incoming connection indications
* (a request to connect) to the <code>count</code> argument. If a
* connection indication arrives when the queue is full, the
* connection is refused.
*
* @param backlog the maximum length of the queue.
* @exception IOException if an I/O error occurs when creating the queue.
*/
protected void listen(int backlog) throws IOException {
return;
}
/**
* Returns the number of bytes that can be read from this socket
* without blocking.
*
* @return the number of bytes that can be read from this socket
* without blocking.
* @exception IOException if an I/O error occurs when determining the
* number of bytes available.
*/
protected int available() throws IOException {
return getInputStream().available();
}
/**
* Returns the value of this socket's <code>fd</code> field.
*
* @return the value of this socket's <code>fd</code> field.
* @see java.net.SocketImpl#fd
*/
protected FileDescriptor getFileDescriptor() {
return new FileDescriptor(); // constructor creates invalid fd
}
/**
* Accepts a connection.
*
* @param s the accepted connection.
* @exception IOException if an I/O error occurs when accepting the
* connection.
*/
protected void accept(SocketImpl s) throws IOException {
((BaseSocketImpl)s).localport = localport;
((BaseSocketImpl)s).acceptConnection();
}
/**
* ignore urgent data
*
* @param d byte of urgent data to (ignore in this case)
* @exception IOException if an error occurs (it can't)
*/
protected void sendUrgentData(int data) throws IOException {
}
protected abstract void acceptConnection() throws IOException;
protected abstract void handleTimer(Object ref);
public void setOption(int optID, Object value)
throws SocketException {
throw new SocketException("option not supported");
}
public Object getOption(int optID) throws SocketException {
throw new SocketException("option not supported");
}
}