[Patches] [ python-Patches-604209 ] release GIL before calling getaddrinfo()

noreply@sourceforge.net noreply@sourceforge.net
Tue, 03 Sep 2002 14:47:38 -0700


Patches item #604209, was opened at 2002-09-03 21:47
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=604209&group_id=5470

Category: Modules
Group: None
>Status: Deleted
Resolution: None
Priority: 5
Submitted By: Jeremy Hylton (jhylton)
Assigned to: Martin v. Löwis (loewis)
Summary: release GIL before calling getaddrinfo()

Initial Comment:
Index: socketmodule.c
===================================================================
RCS file:
/cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.244
diff -c -c -r1.244 socketmodule.c
*** socketmodule.c	3 Sep 2002 19:10:18 -0000	1.244
--- socketmodule.c	3 Sep 2002 21:46:35 -0000
***************
*** 500,506 ****
  /* Do a select() on the socket, if necessary
(sock_timeout > 0).
     The argument writing indicates the direction.
     This does not raise an exception or return a
success indicator;
!    we'll let the actual socket call do that. */
  static void
  internal_select(PySocketSockObject *s, int writing)
  {
--- 500,507 ----
  /* Do a select() on the socket, if necessary
(sock_timeout > 0).
     The argument writing indicates the direction.
     This does not raise an exception or return a
success indicator;
!    we'll let the actual socket call do that. 
! */
  static void
  internal_select(PySocketSockObject *s, int writing)
  {
***************
*** 596,606 ****
--- 597,609 ----
  	memset((void *) addr_ret, '\0', sizeof(*addr_ret));
  	if (name[0] == '\0') {
  		int siz;
+ 		Py_BEGIN_ALLOW_THREADS
  		memset(&hints, 0, sizeof(hints));
  		hints.ai_family = af;
  		hints.ai_socktype = SOCK_DGRAM;	/*dummy*/
  		hints.ai_flags = AI_PASSIVE;
  		error = getaddrinfo(NULL, "0", &hints, &res);
+ 		Py_END_ALLOW_THREADS
  		if (error) {
  			set_gaierror(error);
  			return -1;
***************
*** 648,653 ****
--- 651,657 ----
  		sin->sin_addr.s_addr = INADDR_BROADCAST;
  		return sizeof(sin->sin_addr);
  	}
+ 	Py_BEGIN_ALLOW_THREADS
  	memset(&hints, 0, sizeof(hints));
  	hints.ai_family = af;
  	error = getaddrinfo(name, NULL, &hints, &res);
***************
*** 659,664 ****
--- 663,669 ----
  		error = getaddrinfo(name, NULL, &hints, &res);
  	}
  #endif
+ 	Py_END_ALLOW_THREADS
  	if (error) {
  		set_gaierror(error);
  		return -1;
***************
*** 849,855 ****
  		}
  		if (!PyArg_ParseTuple(args, "si:getsockaddrarg",
&host, &port))
  			return 0;
! 		if (setipaddr(host, (struct sockaddr *)addr,
sizeof(*addr),  AF_INET) < 0)
  			return 0;
  		addr->sin_family = AF_INET;
  		addr->sin_port = htons((short)port);
--- 854,861 ----
  		}
  		if (!PyArg_ParseTuple(args, "si:getsockaddrarg",
&host, &port))
  			return 0;
! 		if (setipaddr(host, (struct sockaddr *)addr,
sizeof(*addr),  
! 			      AF_INET) < 0)
  			return 0;
  		addr->sin_family = AF_INET;
  		addr->sin_port = htons((short)port);
***************
*** 2676,2687 ****
--- 2682,2695 ----
  		PyErr_SetString(socket_error, "Int or String
expected");
  		return NULL;
  	}
+ 	Py_BEGIN_ALLOW_THREADS
  	memset(&hints, 0, sizeof(hints));
  	hints.ai_family = family;
  	hints.ai_socktype = socktype;
  	hints.ai_protocol = protocol;
  	hints.ai_flags = flags;
  	error = getaddrinfo(hptr, pptr, &hints, &res0);
+ 	Py_END_ALLOW_THREADS
  	if (error) {
  		set_gaierror(error);
  		return NULL;
***************
*** 2745,2754 ****
--- 2753,2764 ----
  			       &hostp, &port, &flowinfo, &scope_id))
  		return NULL;
  	PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
+ 	Py_BEGIN_ALLOW_THREADS
  	memset(&hints, 0, sizeof(hints));
  	hints.ai_family = PF_UNSPEC;
  	hints.ai_socktype = SOCK_DGRAM;	/* make numeric port
happy */
  	error = getaddrinfo(hostp, pbuf, &hints, &res);
+ 	Py_END_ALLOW_THREADS
  	if (error) {
  		set_gaierror(error);
  		goto fail;

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=604209&group_id=5470