mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Some UNIX types want the exact size of the address structure
This commit is contained in:
parent
dfd6e46779
commit
710e1df585
1 changed files with 35 additions and 1 deletions
|
@ -317,6 +317,39 @@ getsockaddrarg(s, args, addr_ret, len_ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Get the address length according to the socket object's address family.
|
||||||
|
Return 1 if the family is known, 0 otherwise. The length is returned
|
||||||
|
through len_ret. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
getsockaddrlen(s, len_ret)
|
||||||
|
sockobject *s;
|
||||||
|
int *len_ret;
|
||||||
|
{
|
||||||
|
switch (s->sock_family) {
|
||||||
|
|
||||||
|
case AF_UNIX:
|
||||||
|
{
|
||||||
|
*len_ret = sizeof (struct sockaddr_un);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
case AF_INET:
|
||||||
|
{
|
||||||
|
*len_ret = sizeof (struct sockaddr_in);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* More cases here... */
|
||||||
|
|
||||||
|
default:
|
||||||
|
err_setstr(SocketError, "getsockaddrarg: bad family");
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* s.accept() method */
|
/* s.accept() method */
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
|
@ -329,7 +362,8 @@ sock_accept(s, args)
|
||||||
object *res;
|
object *res;
|
||||||
if (!getnoarg(args))
|
if (!getnoarg(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
addrlen = sizeof addrbuf;
|
if (!getsockaddrlen(s, &addrlen))
|
||||||
|
return NULL;
|
||||||
newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
|
newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
|
||||||
if (newfd < 0)
|
if (newfd < 0)
|
||||||
return socket_error();
|
return socket_error();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue