Changeset 476
- Timestamp:
- 07/23/07 22:43:26 (1 year ago)
- Files:
-
- version_0/java/src/com/rubyeventmachine/Application.java (modified) (3 diffs)
- version_0/java/src/com/rubyeventmachine/Connection.java (modified) (2 diffs)
- version_0/java/src/com/rubyeventmachine/EmReactor.java (modified) (2 diffs)
- version_0/java/src/com/rubyeventmachine/tests/TestDatagrams.java (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/java/src/com/rubyeventmachine/Application.java
r467 r476 36 36 import java.util.*; 37 37 import java.io.*; 38 import java.net.*; 38 39 import java.net.SocketAddress; 39 40 … … 166 167 } catch (IOException e) {} 167 168 } 169 170 public void sendDatagram (String sig, ByteBuffer bb, InetSocketAddress target) { 171 reactor.sendDatagram(sig, bb, target.getHostName(), target.getPort()); 172 } 173 168 174 public void closeConnection (String sig, boolean afterWriting) { 169 175 try { … … 171 177 } catch (ClosedChannelException e) {} 172 178 } 179 180 public void openDatagramSocket (Connection c) { 181 openDatagramSocket (new InetSocketAddress ("0.0.0.0", 0), c); 182 } 183 public void openDatagramSocket (InetSocketAddress addr, Connection c) { 184 try { 185 String s = reactor.openUdpSocket(addr); 186 c.application = this; 187 c.signature = s; 188 reactor.connections.put(s, c); 189 c.postInit(); 190 } catch (ClosedChannelException e) { 191 } catch (IOException e) { 192 System.out.println ("Bad Datagram socket "+e+" "+addr); 193 /* TODO, can't catch this here, because it can happen on a bad address */ 194 } 195 } 173 196 } version_0/java/src/com/rubyeventmachine/Connection.java
r467 r476 33 33 //import java.io.*; 34 34 import java.nio.*; 35 import java.net.*; 35 36 //import java.nio.channels.*; 36 37 … … 67 68 application.closeConnection(signature, true); 68 69 } 70 71 public void sendDatagram (ByteBuffer bb, InetSocketAddress addr) { 72 application.sendDatagram (signature, bb, addr); 73 } 69 74 } version_0/java/src/com/rubyeventmachine/EmReactor.java
r464 r476 285 285 286 286 287 public String openUdpSocket (String address, int port) throws IOException { 288 return openUdpSocket (new InetSocketAddress (address, port)); 289 } 287 290 /** 288 291 * … … 292 295 * @throws IOException 293 296 */ 294 public String openUdpSocket (String address, int port) throws IOException { 297 public String openUdpSocket (InetSocketAddress address) throws IOException { 298 // TODO, don't throw an exception out of here. 295 299 DatagramChannel dg = DatagramChannel.open(); 296 300 dg.configureBlocking(false); 297 dg.socket().bind( new InetSocketAddress(address,port));301 dg.socket().bind(address); 298 302 String b = createBinding(); 299 303 EventableChannel ec = new EventableDatagramChannel (dg, b, mySelector);