Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: frog/lib/node/net.dart

Issue 9034014: Add support for the node net module. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: new version of minfrog Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « frog/lib/node/http.dart ('k') | frog/lib/node/node.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library('net');
6 #import('node.dart');
7
8 class net native "require('net')" {
9 static Server createServer([ServerConnectionListener connectionListener,
10 Map options]) native;
11
12 static Socket createConnection(int port, [String hostName,
13 SocketConnectListener connectListener]) native;
14
15 static Socket createUnixConnection(String path,
16 [SocketConnectListener connectListener])
17 native "return this.createConnection(path,connectListener)";
sra1 2012/01/23 07:25:37 'this' makes no sense in a static method. Perhaps
jackpal 2012/01/23 13:13:38 I am pretty sure the "this" is required. The Dart
18
19 static int isIP(String input) native;
20 static bool isIPv4(String input) native;
21 static bool isIPv6(String input) native;
22 }
23
24 typedef void ServerListeningListener();
25 typedef void ServerConnectionListener(Socket socket);
26 typedef void ServerCloseListener();
27 typedef void ServerErrorListener(Error e);
28
29 // TODO(jackpal): resolve name conflict with http.Server. Maybe both should go
30 // into their own libraries.
31
32 class Server implements EventEmitter native "require('net').Server" {
33 // EventEmitter
34 void removeAllListeners(String event) native;
35 void setMaxListeners(num n) native;
36 var _listeners(String key)
37 native "return this.listeners(key);";
38
39 // event 'listening'
40 void emitListening()
41 native "this.emit('listening');";
42 void addListenerListening(ServerListeningListener listener)
43 native "this.addListener('listening', listener);";
44 void onListening(ServerListeningListener listener)
45 native "this.on('listening', listener);";
46 void onceListening(ServerListeningListener listener)
47 native "this.once('listening', listener);";
48 void removeListenerListening(ServerListeningListener listener)
49 native "this.removeListener('listening', listener);";
50 List<ServerListeningListener> listenersListening()
51 => new _NativeListPrimitiveElement<ServerListeningListener>(
52 _listeners('listening'));
53
54 // event 'connection'
55 void emitConnection()
56 native "this.emit('connection');";
57 void addListenerConnection(ServerConnectionListener listener)
58 native "this.addListener('connection', listener);";
59 void onConnection(ServerConnectionListener listener)
60 native "this.on('connection', listener);";
61 void onceConnection(ServerConnectionListener listener)
62 native "this.once('connection', listener);";
63 void removeListenerConnection(ServerConnectionListener listener)
64 native "this.removeListener('connection', listener);";
65 List<ServerConnectionListener> listenersConnection()
66 => new _NativeListPrimitiveElement<ServerConnectionListener>(
67 _listeners('connection'));
68
69 // event 'close'
70 void emitClose()
71 native "this.emit('close');";
72 void addListenerClose(ServerCloseListener listener)
73 native "this.addListener('close', listener);";
74 void onClose(ServerCloseListener listener)
75 native "this.on('close', listener);";
76 void onceClose(ServerCloseListener listener)
77 native "this.once('close', listener);";
78 void removeListenerClose(ServerCloseListener listener)
79 native "this.removeListener('close', listener);";
80 List<ServerCloseListener> listenersClose()
81 => new _NativeListPrimitiveElement<ServerCloseListener>(
82 _listeners('close'));
83
84 // event 'error'
85 void emitError()
86 native "this.emit('error');";
87 void addListenerError(ServerErrorListener listener)
88 native "this.addListener('error', listener);";
89 void onError(ServerErrorListener listener)
90 native "this.on('error', listener);";
91 void onceError(ServerErrorListener listener)
92 native "this.once('error', listener);";
93 void removeListenerError(ServerErrorListener listener)
94 native "this.removeListener('error', listener);";
95 List<ServerErrorListener> listenersError()
96 => new _NativeListPrimitiveElement<ServerErrorListener>(
97 _listeners('error'));
98
99 void listen(int port, [String host,
100 ServerListeningListener listeningListener]) native;
101 void listenUnix(String path,
102 [ServerListeningListener listeningListener])
103 native "this.listen(path, listeningListener);";
104 void pause([int msecs]) native;
105 void close() native;
106 String address() native;
107 int maxConnections;
108 int connections;
109 }
110
111 typedef void SocketConnectListener();
112 typedef void SocketTimeoutListener();
113 typedef void SocketCloseListener(bool had_error);
114
115 class Socket implements ReadWriteStream native "require('net').Socket" {
116 // EventEmitter
117 void removeAllListeners(String event) native;
118 void setMaxListeners(num n) native;
119 var _listeners(String key)
120 native "return this.listeners(key);";
121
122 // CommonStream
123
124 // Error event
125 void emitError(Error error)
126 native "this.emit('error', error);";
127 void addListenerError(StreamErrorListener listener)
128 native "this.addListener('error', listener);";
129 void onError(StreamErrorListener listener)
130 native "this.on('error', listener);";
131 void onceError(StreamErrorListener listener)
132 native "this.once('error', listener);";
133 void removeListenerError(StreamErrorListener listener)
134 native "this.removeListener('error', listener);";
135 List<StreamErrorListener> listenersError()
136 => new _NativeListPrimitiveElement<StreamErrorListener>(
137 _listeners('error'));
138
139 // Close event
140 void emitClose()
141 native "this.emit('close');";
142 void addListenerClose(StreamCloseListener listener)
143 native "this.addListener('close', listener);";
144 void onClose(StreamCloseListener listener)
145 native "this.on('close', listener);";
146 void onceClose(StreamCloseListener listener)
147 native "this.once('close', listener);";
148 void removeListenerClose(StreamCloseListener listener)
149 native "this.removeListener('close', listener);";
150 List<StreamCloseListener> listenersClose()
151 => new _NativeListPrimitiveElement<StreamCloseListener>(
152 _listeners('close'));
153
154 // ReadableStream
155
156 // Data event
157 void emitData(var data)
158 native "this.emit('data', data);";
159 void addListenerData(ReadableStreamDataListener listener)
160 native "this.addListener('data', listener);";
161 void onData(ReadableStreamDataListener listener)
162 native "this.on('data', listener);";
163 void onceData(ReadableStreamDataListener listener)
164 native "this.once('data', listener);";
165 void removeListenerData(ReadableStreamDataListener listener)
166 native "this.removeListener('data', listener);";
167 List<ReadableStreamDataListener> listenersData()
168 => new _NativeListPrimitiveElement<ReadableStreamDataListener>(
169 _listeners('data'));
170
171 // End event
172 void emitEnd()
173 native "this.emit('end');";
174 void addListenerEnd(ReadableStreamEndListener listener)
175 native "this.addListener('end', listener);";
176 void onEnd(ReadableStreamEndListener listener)
177 native "this.on('end', listener);";
178 void onceEnd(ReadableStreamEndListener listener)
179 native "this.once('end', listener);";
180 void removeListenerEnd(ReadableStreamEndListener listener)
181 native "this.removeListener('end', listener);";
182 List<ReadableStreamEndListener> listenersEnd()
183 => new _NativeListPrimitiveElement<ReadableStreamEndListener>(
184 _listeners('end'));
185
186 bool readable;
187 void setEncoding(String encoding) native;
188 void pause() native;
189 void resume() native;
190 void destroy() native;
191 void destroySoon() native;
192 WritableStream pipe(WritableStream destination, [Map options]) native;
193
194 // WritableStream
195
196 // Drain event
197 void emitDrain()
198 native "this.emit('drain');";
199 void addListenerDrain(WritableStreamDrainListener listener)
200 native "this.addListener('drain', listener);";
201 void onDrain(WritableStreamDrainListener listener)
202 native "this.on('drain', listener);";
203 void onceDrain(WritableStreamDrainListener listener)
204 native "this.once('drain', listener);";
205 void removeListenerDrain(WritableStreamDrainListener listener)
206 native "this.removeListener('drain', listener);";
207 List<WritableStreamDrainListener> listenersDrain()
208 => new _NativeListPrimitiveElement<WritableStreamDrainListener>(
209 _listeners('drain'));
210
211 // Pipe event
212 void emitPipe(ReadableStream src)
213 native "this.emit('pipe', src);";
214 void addListenerPipe(WritableStreamPipeListener listener)
215 native "this.addListener('pipe', listener);";
216 void onPipe(WritableStreamPipeListener listener)
217 native "this.on('pipe', listener);";
218 void oncePipe(WritableStreamPipeListener listener)
219 native "this.once('pipe', listener);";
220 void removeListenerPipe(WritableStreamPipeListener listener)
221 native "this.removeListener('pipe', listener);";
222 List<WritableStreamPipeListener> listenersPipe()
223 => new _NativeListPrimitiveElement<WritableStreamPipeListener>(
224 _listeners('pipe'));
225
226 bool writable;
227 bool write(String string, [String encoding, int fd]) native;
228 bool writeBuffer(Buffer buffer) native;
229 void end([String string, String encoding]) native;
230 void endBuffer(Buffer buffer) native "this.end(buffer);";
231 }
OLDNEW
« no previous file with comments | « frog/lib/node/http.dart ('k') | frog/lib/node/node.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698