@@ -42,14 +42,16 @@ cdef class UVTCPServer(UVTcpStream):
42
42
cdef _init(self ):
43
43
UVTcpStream._init(< UVTcpStream> self )
44
44
self .protocol_factory = None
45
+ self .host_server = None
45
46
46
47
@staticmethod
47
- cdef UVTCPServer new(Loop loop, object protocol_factory):
48
+ cdef UVTCPServer new(Loop loop, object protocol_factory, Server server ):
48
49
cdef UVTCPServer handle
49
50
handle = UVTCPServer.__new__ (UVTCPServer)
50
51
handle._set_loop(loop)
51
52
handle._init()
52
53
handle._set_protocol_factory(protocol_factory)
54
+ handle.host_server = server
53
55
return handle
54
56
55
57
cdef _set_protocol_factory(self , object protocol_factory):
@@ -88,7 +90,7 @@ cdef class UVTCPServer(UVTcpStream):
88
90
89
91
cdef _on_listen(self ):
90
92
protocol = self .protocol_factory()
91
- client = UVServerTransport.new(self ._loop, protocol)
93
+ client = UVServerTransport.new(self ._loop, protocol, self .host_server )
92
94
client._accept(< UVStream> self )
93
95
94
96
@@ -112,12 +114,15 @@ cdef class UVServerTransport(UVTcpStream):
112
114
self .low_water = FLOW_CONTROL_LOW_WATER
113
115
114
116
@staticmethod
115
- cdef UVServerTransport new(Loop loop, object protocol):
117
+ cdef UVServerTransport new(Loop loop, object protocol, Server server ):
116
118
cdef UVServerTransport handle
117
119
handle = UVServerTransport.__new__ (UVServerTransport)
118
120
handle._set_loop(loop)
119
121
handle._init()
120
122
handle._set_protocol(protocol)
123
+ handle.host_server = server
124
+ if server is not None :
125
+ (< Server> server)._attach()
121
126
return handle
122
127
123
128
cdef _set_protocol(self , object protocol):
@@ -210,15 +215,37 @@ cdef class UVServerTransport(UVTcpStream):
210
215
' protocol' : self .protocol,
211
216
})
212
217
218
+ cdef _call_connection_lost(self , exc):
219
+ try :
220
+ if self .protocol is not None :
221
+ self .protocol.connection_lost(exc)
222
+ finally :
223
+ self .protocol = None
224
+ self .protocol_data_received = None
225
+
226
+ self ._close()
227
+
228
+ server = self .host_server
229
+ if server is not None :
230
+ server._detach()
231
+ self .host_server = None
232
+
233
+ cdef _report_callback_error(self , exc):
234
+ self ._call_connection_lost(exc)
235
+ super ()._report_callback_error(exc)
236
+
237
+ cdef _raise_fatal_error(self , exc):
238
+ self ._call_connection_lost(exc)
239
+ super ()._raise_fatal_error(exc)
240
+
213
241
# Public API
214
242
215
243
property _closing :
216
244
def __get__ (self ):
217
- # "self._closing" refers to "UVHandle._closing" cdef
218
- return (< UVHandle> self )._closing or (< UVHandle> self )._closed
245
+ return (< UVHandle> self )._closed
219
246
220
247
def is_closing (self ):
221
- return (< UVHandle> self )._closing or ( < UVHandle > self ). _closed
248
+ return (< UVHandle> self )._closed
222
249
223
250
def write (self , object buf ):
224
251
self ._write(buf, None )
@@ -279,23 +306,8 @@ cdef class UVServerTransport(UVTcpStream):
279
306
return (self ._low_water, self ._high_water)
280
307
281
308
def get_extra_info (self , name , default = None ):
282
- cdef:
283
- int buf_len = sizeof(system.sockaddr_storage)
284
- int err
285
- system.sockaddr_storage buf
286
-
287
309
if name == ' socket' :
288
- err = uv.uv_tcp_getsockname(< uv.uv_tcp_t* > self ._handle,
289
- < system.sockaddr* > & buf,
290
- & buf_len)
291
- if err < 0 :
292
- self ._close()
293
- raise convert_error(err)
294
-
295
- return socket_fromfd(self ._fileno(),
296
- buf.ss_family,
297
- uv.SOCK_STREAM)
298
-
310
+ return self ._get_socket()
299
311
return default
300
312
301
313
def abort (self ):
0 commit comments