[ 
https://issues.apache.org/jira/browse/THRIFT-4668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16695516#comment-16695516
 ] 

ASF GitHub Bot commented on THRIFT-4668:
----------------------------------------

lshgdut commented on a change in pull request #1631: THRIFT-4668: make socket 
backlog configurable for python
URL: https://github.com/apache/thrift/pull/1631#discussion_r235592274
 
 

 ##########
 File path: lib/py/src/transport/TSocket.py
 ##########
 @@ -183,7 +187,7 @@ def listen(self):
         if hasattr(self.handle, 'settimeout'):
             self.handle.settimeout(None)
         self.handle.bind(res[4])
-        self.handle.listen(128)
+        self.handle.listen(self._backlog)
 
 Review comment:
   We shoud not use `self.handle.listen(self._backlog or 128)` to preserve the 
existing behavior, because the backlog parameter accept a zero value.
   Plz have a look at the python source code below:
   ```c
   // From Python-2.7.14/Modules/socketmodule.c
   /* s.listen(n) method */
   
   static PyObject *
   sock_listen(PySocketSockObject *s, PyObject *arg)
   {
       // some code before
       /* To avoid problems on systems that don't allow a negative backlog
        * (which doesn't make sense anyway) we force a minimum value of 0. */
       if (backlog < 0)
           backlog = 0;
       res = listen(s->sock_fd, backlog);
       // some code more
   }
   ```
   
   I have think about `self._backlog if self._backlog is None else 128 `, and 
the code seems to be redundant with bad smell. So declaring the _backlog 
attribute with a default value of 128 in the class constructor seems to be a 
better way, isn't? On the other hand, `__init__` will be called before listen, 
while the listen method called, `this.handle.listen` will receive a `_backlog` 
with a default value of 128,  existing behavior preserved!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> make socket backlog configurable for python
> -------------------------------------------
>
>                 Key: THRIFT-4668
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4668
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Python - Library
>    Affects Versions: 0.11.0
>            Reporter: lsh
>            Priority: Minor
>              Labels: patch
>
> The backlog parameter of socket.listen was hard coded, so I can't customize 
> it in my code.
> Adding `setBacklog` to `TServerSocket` can resolve my problem. :)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to