PageRenderTime 37ms CodeModel.GetById 13ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/toolkit/trunk/toolkit/src/jist/swans/app/net/Socket.java

https://bitbucket.org/leontiad/srijan-java-app
Java | 472 lines | 229 code | 64 blank | 179 comment | 0 complexity | f08f87ccf15813f82b1c0e09d987597c MD5 | raw file
  1//////////////////////////////////////////////////
  2// JIST (Java In Simulation Time) Project
  3// Timestamp: <Socket.java Tue 2004/04/06 11:45:57 barr pompom.cs.cornell.edu>
  4//
  5
  6// Copyright (C) 2004 by Cornell University
  7// All rights reserved.
  8// Refer to LICENSE for terms and conditions of use.
  9
 10package jist.swans.app.net;
 11
 12import java.nio.channels.SocketChannel;
 13import java.net.SocketImplFactory;
 14import java.net.SocketImpl;
 15import java.net.InetAddress;
 16import java.net.SocketAddress;
 17import jist.swans.app.io.InputStream;
 18import jist.swans.app.io.OutputStream;
 19import java.io.IOException;
 20
 21import jist.swans.app.AppInterface;
 22import jist.swans.trans.SocketInterface;
 23import jist.swans.trans.TcpSocket;
 24import jist.runtime.JistAPI;
 25
 26/**
 27 * The SWANS target of all java.net.Socket calls.
 28 *
 29 * @author Rimon Barr &lt;barr+jist@cs.cornell.edu&rt;
 30 * @version $Id: Socket.java,v 1.1 2006/10/21 00:04:00 lmottola Exp $
 31 * @since SWANS1.0
 32 */
 33public class Socket
 34{
 35
 36  //////////////////////////////////////////////////
 37  // Private Variables
 38  //
 39
 40  /** supporting socket entity. */
 41  private SocketInterface.TcpSocketInterface socketEntity;
 42
 43
 44  //////////////////////////////////////////////////
 45  // Constructors
 46  //
 47
 48  /**
 49   * @see java.net.Socket
 50   */
 51  public Socket()
 52  { 
 53    TcpSocket newSocketEntity = new TcpSocket();
 54    socketEntity = newSocketEntity.getProxy();
 55  }
 56
 57  /**
 58   * @see java.net.Socket
 59   */
 60  public Socket(InetAddress address, int port)
 61  {
 62    TcpSocket newSocketEntity = new TcpSocket(address, port);
 63    socketEntity = newSocketEntity.getProxy();
 64  }
 65
 66  /**
 67   * @see java.net.Socket
 68   */
 69  public Socket(InetAddress host, int port, boolean stream)
 70  {
 71    TcpSocket newSocketEntity = new TcpSocket(host, port, stream);
 72    socketEntity = newSocketEntity.getProxy();
 73  }
 74
 75  /**
 76   * @see java.net.Socket
 77   */
 78  public Socket(InetAddress address, int port, InetAddress localAddr, int localPort)
 79  {
 80    TcpSocket newSocketEntity = new TcpSocket(address, port, localAddr, localPort);
 81    socketEntity = newSocketEntity.getProxy();
 82  }
 83
 84  /**
 85   * @see java.net.Socket
 86   */
 87  protected Socket(SocketImpl impl)
 88  {
 89    throw new RuntimeException("not implemented");
 90  }
 91
 92  /**
 93   * @see java.net.Socket
 94   */
 95  public Socket(String host, int port)
 96  {
 97    TcpSocket newSocketEntity = new TcpSocket(host, port);
 98    socketEntity = newSocketEntity.getProxy();
 99  }
100
101  /**
102   * @see java.net.Socket
103   */
104  public Socket(String host, int port, boolean stream)
105  {
106    throw new RuntimeException("not implemented");
107  }
108
109  /**
110   * @see java.net.Socket
111   */
112  public Socket(String host, int port, InetAddress localAddr, int localPort)
113  {
114    TcpSocket newSocketEntity = new TcpSocket(host, port, localAddr, localPort);
115    socketEntity = newSocketEntity.getProxy();
116  }
117
118  /**
119   * @see java.net.Socket
120   */
121  public Socket(TcpSocket socket)
122  {
123    this.socketEntity = socket.getProxy();
124  }
125
126  /**
127   * Method call after socket initialization. Since constructors can not be
128   * blocking, we performing blocking events in this method, which is called
129   * immediately after the constructor.
130   */
131  public void _jistPostInit()
132  {
133    socketEntity.setTcpEntity(((AppInterface.TcpApp)JistAPI.proxy(JistAPI.THIS, AppInterface.TcpApp.class)).getTcpEntity());
134    socketEntity._jistPostInit();
135  }
136
137
138  //////////////////////////////////////////////////
139  // Socket methods
140  //
141
142  /**
143   * @see java.net.Socket
144   */
145  public void bind(SocketAddress bindpoint)
146  {
147    socketEntity.bind(bindpoint);
148  }
149
150  /**
151   * @see java.net.Socket
152   */
153  public void close()
154  {
155    JistAPI.sleep(1000);
156    socketEntity.close();
157  }
158
159  /**
160   * @see java.net.Socket
161   */
162  public void connect(SocketAddress endpoint)
163  {
164    socketEntity.connect(endpoint);
165  }
166
167  /**
168   * @see java.net.Socket
169   */
170  public void connect(SocketAddress endpoint, int timeout)
171  {
172    socketEntity.connect(endpoint, timeout);
173  }
174
175  /**
176   * @see java.net.Socket
177   */
178  public SocketChannel getChannel()
179  {
180    return socketEntity.getChannel();
181  }
182
183  /**
184   * @see java.net.Socket
185   */
186  public InetAddress getInetAddress()
187  {
188    return socketEntity.getInetAddress();
189  }
190
191  /**
192   * @see java.net.Socket
193   */
194  public InputStream getInputStream()
195  {
196    return socketEntity.getInputStream();
197  }
198
199  /**
200   * @see java.net.Socket
201   */
202  public boolean getKeepAlive()
203  {
204    return socketEntity.getKeepAlive();
205  }
206
207  /**
208   * @see java.net.Socket
209   */
210  public InetAddress getLocalAddress()
211  {
212    return socketEntity.getLocalAddress();
213  }
214
215  /**
216   * @see java.net.Socket
217   */
218  public int getLocalPort()
219  {
220    return socketEntity.getLocalPort();
221  }
222
223  /**
224   * @see java.net.Socket
225   */
226  public SocketAddress getLocalSocketAddress()
227  {
228    return socketEntity.getLocalSocketAddress();
229  }
230
231  /**
232   * @see java.net.Socket
233   */
234  public boolean getOOBInline()
235  {
236    return socketEntity.getOOBInline();
237  }
238
239  /**
240   * @see java.net.Socket
241   */
242  public OutputStream getOutputStream()
243  {
244    return socketEntity.getOutputStream();
245  }
246
247  /**
248   * @see java.net.Socket
249   */
250  public int getPort()
251  {
252    return socketEntity.getPort();
253  }
254
255  /**
256   * @see java.net.Socket
257   */
258  public int getReceiveBufferSize()
259  {
260    return socketEntity.getReceiveBufferSize();
261  }
262
263  /**
264   * @see java.net.Socket
265   */
266  public SocketAddress getRemoteSocketAddress()
267  {
268    return socketEntity.getRemoteSocketAddress();
269  }
270
271  /**
272   * @see java.net.Socket
273   */
274  public boolean getReuseAddress()
275  {
276    return socketEntity.getReuseAddress();
277  }
278
279  /**
280   * @see java.net.Socket
281   */
282  public int getSendBufferSize()
283  {
284    return socketEntity.getSendBufferSize();
285  }
286
287  /**
288   * @see java.net.Socket
289   */
290  public int getSoLinger()
291  {
292    return socketEntity.getSoLinger();
293  }
294
295  /**
296   * @see java.net.Socket
297   */
298  public int getSoTimeout()
299  {
300    return socketEntity.getSoTimeout();
301  }
302
303  /**
304   * @see java.net.Socket
305   */
306  public boolean getTcpNoDelay()
307  {
308    return socketEntity.getTcpNoDelay();
309  }
310
311  /**
312   * @see java.net.Socket
313   */
314  public int getTrafficClass()
315  {
316    return socketEntity.getTrafficClass();
317  }
318
319  /**
320   * @see java.net.Socket
321   */
322  public boolean isBound()
323  {
324    return socketEntity.isBound();
325  }
326
327  /**
328   * @see java.net.Socket
329   */
330  public boolean isClosed()
331  {
332    return socketEntity.isClosed();
333  }
334
335  /**
336   * @see java.net.Socket
337   */
338  public boolean isConnected()
339  {
340    return socketEntity.isConnected();
341  }
342
343  /**
344   * @see java.net.Socket
345   */
346  public boolean isInputShutdown()
347  {
348    return socketEntity.isInputShutdown();
349  }
350
351  /**
352   * @see java.net.Socket
353   */
354  public boolean isOutputShutdown()
355  {
356    return socketEntity.isOutputShutdown();
357  }
358
359  /**
360   * @see java.net.Socket
361   */
362  public void sendUrgentData(int data)
363  {
364    socketEntity.sendUrgentData(data);
365  }
366
367  /**
368   * @see java.net.Socket
369   */
370  public void setKeepAlive(boolean on)
371  {
372    socketEntity.setKeepAlive(on);
373  }
374
375  /**
376   * @see java.net.Socket
377   */
378  public void setOOBInline(boolean on)
379  {
380    socketEntity.setOOBInline(on);
381  }
382
383  /**
384   * @see java.net.Socket
385   */
386  public void setReceiveBufferSize(int size)
387  {
388    socketEntity.setReceiveBufferSize(size);
389  }
390
391  /**
392   * @see java.net.Socket
393   */
394  public void setReuseAddress(boolean on)
395  {
396    socketEntity.setReuseAddress(on);
397  }
398
399  /**
400   * @see java.net.Socket
401   */
402  public void setSendBufferSize(int size)
403  {
404    socketEntity.setSendBufferSize(size);
405  }
406
407  /**
408   * @see java.net.Socket
409   */
410  public static void setSocketImplFactory(SocketImplFactory fac)
411  {
412    throw new RuntimeException("not implemented");
413  }
414
415  /**
416   * @see java.net.Socket
417   */
418  public void setSoLinger(boolean on, int linger)
419  {
420    socketEntity.setSoLinger(on, linger);
421  }
422
423  /**
424   * @see java.net.Socket
425   */
426  public void setSoTimeout(int timeout)
427  {
428    socketEntity.setSoTimeout(timeout);
429  }
430
431  /**
432   * @see java.net.Socket
433   */
434  public void setTcpNoDelay(boolean on)
435  {
436    socketEntity.setTcpNoDelay(on);
437  }
438
439  /**
440   * @see java.net.Socket
441   */
442  public void setTrafficClass(int tc)
443  {
444    socketEntity.setTrafficClass(tc);
445  }
446
447  /**
448   * @see java.net.Socket
449   */
450  public void shutdownInput() throws IOException
451  {
452    socketEntity.shutdownInput();
453  }
454
455  /**
456   * @see java.net.Socket
457   */
458  public void shutdownOutput() throws IOException
459  {
460    socketEntity.shutdownOutput();
461  }
462
463  /**
464   * @see java.net.Socket
465   */
466  public String toString()
467  {
468    return socketEntity.toString();
469  }
470
471} // class Socket
472