71 self.registerRequestHandler( |
71 self.registerRequestHandler( |
72 EricRequestCategory.Coverage, |
72 EricRequestCategory.Coverage, |
73 self.__coverageRequestHandler.handleRequest, |
73 self.__coverageRequestHandler.handleRequest, |
74 ) |
74 ) |
75 |
75 |
76 # TODO: 'Project' handler not implemented yet |
|
77 # TODO: implement an 'EditorConfig' handler (?) |
76 # TODO: implement an 'EditorConfig' handler (?) |
78 |
77 |
79 self.__address = ("", port) |
78 self.__address = ("", port) |
80 self.__useIPv6 = useIPv6 |
79 self.__useIPv6 = useIPv6 |
81 |
80 |
201 }, |
200 }, |
202 ) |
201 ) |
203 return {} |
202 return {} |
204 |
203 |
205 jsonStr = data.decode("utf8", "backslashreplace") |
204 jsonStr = data.decode("utf8", "backslashreplace") |
206 # - print("Eric Server Receive:", jsonStr) # for debugging |
205 print("Eric Server Receive:", jsonStr) # for debugging |
207 try: |
206 try: |
208 return json.loads(jsonStr.strip()) |
207 return json.loads(jsonStr.strip()) |
209 except (TypeError, ValueError) as err: |
208 except (TypeError, ValueError) as err: |
210 self.sendJson( |
209 self.sendJson( |
211 category=EricRequestCategory.Error, |
210 category=EricRequestCategory.Error, |
279 self.__address, family=socket.AF_INET, backlog=0 |
278 self.__address, family=socket.AF_INET, backlog=0 |
280 ) |
279 ) |
281 |
280 |
282 self.__socket.listen(0) |
281 self.__socket.listen(0) |
283 self.__socket.setblocking(False) |
282 self.__socket.setblocking(False) |
284 print(f"Listening for 'eric-ide' connections on {self.__socket.getsockname()}") |
283 address = self.__socket.getsockname() |
285 # noqa: M801 |
284 print( # noqa: M801 |
|
285 f"Listening for 'eric-ide' connections on {address[0]}, port {address[1]}" |
|
286 ) |
286 data = types.SimpleNamespace( |
287 data = types.SimpleNamespace( |
287 name="server", acceptHandler=self.__acceptIdeConnection |
288 name="server", acceptHandler=self.__acceptIdeConnection |
288 ) |
289 ) |
289 self.__selector.register(self.__socket, selectors.EVENT_READ, data=data) |
290 self.__selector.register(self.__socket, selectors.EVENT_READ, data=data) |
290 |
291 |
318 @param sock reference to the listening socket |
319 @param sock reference to the listening socket |
319 @type socket.socket |
320 @type socket.socket |
320 """ |
321 """ |
321 connection, address = sock.accept() # Should be ready to read |
322 connection, address = sock.accept() # Should be ready to read |
322 if self.__connection is None: |
323 if self.__connection is None: |
323 print(f"'eric-ide' connection from {address[0]}, port {address[1]}") |
324 print(f"'eric-ide' connection from {address[0]}, port {address[1]}") |
324 # noqa: M801 |
325 # noqa: M801 |
325 self.__connection = connection |
326 self.__connection = connection |
326 self.__connection.setblocking(False) |
327 ##self.__connection.setblocking(False) |
327 data = types.SimpleNamespace( |
328 data = types.SimpleNamespace( |
328 name="eric-ide", address=address, handler=self.__serviceIdeConnection |
329 name="eric-ide", address=address, handler=self.__serviceIdeConnection |
329 ) |
330 ) |
330 events = selectors.EVENT_READ |
331 events = selectors.EVENT_READ |
331 self.__selector.register(self.__connection, events, data=data) |
332 self.__selector.register(self.__connection, events, data=data) |
332 |
333 |
333 self.__unregisterIdeSocket() |
334 self.__unregisterIdeSocket() |
334 else: |
335 else: |
335 print( # noqa: M801 |
336 print( # noqa: M801 |
336 f"'eric-ide' connection from {address[0]}, port {address[1]} rejected" |
337 f"'eric-ide' connection from {address[0]}, port {address[1]} rejected" |
337 ) |
338 ) |
338 connection.close() |
339 connection.close() |
339 |
340 |
340 def __closeIdeConnection(self, shutdown=False): |
341 def __closeIdeConnection(self, shutdown=False): |
341 """ |
342 """ |
345 @type bool |
346 @type bool |
346 """ |
347 """ |
347 if self.__connection is not None: |
348 if self.__connection is not None: |
348 self.__selector.unregister(self.__connection) |
349 self.__selector.unregister(self.__connection) |
349 try: |
350 try: |
|
351 address = self.__connection.getpeername() |
350 print( # noqa: M801 |
352 print( # noqa: M801 |
351 f"Closing 'eric-ide' connection to" |
353 f"Closing 'eric-ide' connection to {address[0]}, port {address[1]}." |
352 f" {self.__connection.getpeername()}." |
|
353 ) |
354 ) |
354 self.__connection.shutdown(socket.SHUT_RDWR) |
355 self.__connection.shutdown(socket.SHUT_RDWR) |
355 self.__connection.close() |
356 self.__connection.close() |
356 except OSError: |
357 except OSError: |
357 print("'eric-ide' connection gone.") # noqa: M801 |
358 print("'eric-ide' connection gone.") # noqa: M801 |