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