摘要 |
A method for processing a Socket and apparatus and a Web server are provided. The method for processing a Socket is applied in a Web server. The Web server is based on a platform for providing an asynchronous unblocking-mode Socket. The method includes: monitoring a client request of a port of the Web server; according to the monitored client request, registering a Socket event through an asynchronous selection operation; judging whether the Socket event is a READ event and/or a WRITE event, to obtain a judgment result; when the judgment result indicates that the Socket event is a READ event and/or a WRITE event, starting timing; and when the timing reaches a preset threshold and the Web task does not receive a first semaphore sent by a Socket underlying layer, sending a second semaphore to the Web task, so that the Web task can be activated, and a corresponding procedure is processed according to the Socket event. In the embodiments of the present invention, when an exception occurs at a client, a Web server can still be accessed. |