Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ae0013d3
Commit
ae0013d3
authored
Oct 11, 2001
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert socket methods to use METH_O and METH_NOARGS where possible.
parent
cb43c085
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
50 deletions
+39
-50
Modules/socketmodule.c
Modules/socketmodule.c
+39
-50
No files found.
Modules/socketmodule.c
View file @
ae0013d3
...
...
@@ -925,7 +925,7 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
/* s.accept() method */
static
PyObject
*
PySocketSock_accept
(
PySocketSockObject
*
s
,
PyObject
*
args
)
PySocketSock_accept
(
PySocketSockObject
*
s
)
{
char
addrbuf
[
256
];
SOCKET_T
newfd
;
...
...
@@ -934,8 +934,6 @@ PySocketSock_accept(PySocketSockObject *s, PyObject *args)
PyObject
*
addr
=
NULL
;
PyObject
*
res
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
":accept"
))
return
NULL
;
if
(
!
getsockaddrlen
(
s
,
&
addrlen
))
return
NULL
;
memset
(
addrbuf
,
0
,
addrlen
);
...
...
@@ -983,7 +981,7 @@ info is a pair (hostaddr, port).";
/* s.setblocking(1 | 0) method */
static
PyObject
*
PySocketSock_setblocking
(
PySocketSockObject
*
s
,
PyObject
*
arg
s
)
PySocketSock_setblocking
(
PySocketSockObject
*
s
,
PyObject
*
arg
)
{
int
block
;
#ifndef RISCOS
...
...
@@ -991,7 +989,8 @@ PySocketSock_setblocking(PySocketSockObject *s, PyObject *args)
int
delay_flag
;
#endif
#endif
if
(
!
PyArg_ParseTuple
(
args
,
"i:setblocking"
,
&
block
))
block
=
PyInt_AsLong
(
arg
);
if
(
block
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
Py_BEGIN_ALLOW_THREADS
#ifdef __BEOS__
...
...
@@ -1158,14 +1157,12 @@ string of that length; otherwise it is an integer.";
/* s.bind(sockaddr) method */
static
PyObject
*
PySocketSock_bind
(
PySocketSockObject
*
s
,
PyObject
*
a
rgs
)
PySocketSock_bind
(
PySocketSockObject
*
s
,
PyObject
*
a
ddro
)
{
struct
sockaddr
*
addr
;
int
addrlen
;
int
res
;
PyObject
*
addro
;
if
(
!
PyArg_ParseTuple
(
args
,
"O:bind"
,
&
addro
))
return
NULL
;
if
(
!
getsockaddrarg
(
s
,
addro
,
&
addr
,
&
addrlen
))
return
NULL
;
Py_BEGIN_ALLOW_THREADS
...
...
@@ -1190,11 +1187,10 @@ sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])";
will surely fail. */
static
PyObject
*
PySocketSock_close
(
PySocketSockObject
*
s
,
PyObject
*
args
)
PySocketSock_close
(
PySocketSockObject
*
s
)
{
SOCKET_T
fd
;
if
(
!
PyArg_ParseTuple
(
args
,
":close"
))
return
NULL
;
if
((
fd
=
s
->
sock_fd
)
!=
-
1
)
{
s
->
sock_fd
=
-
1
;
Py_BEGIN_ALLOW_THREADS
...
...
@@ -1214,14 +1210,12 @@ Close the socket. It cannot be used after this call.";
/* s.connect(sockaddr) method */
static
PyObject
*
PySocketSock_connect
(
PySocketSockObject
*
s
,
PyObject
*
a
rgs
)
PySocketSock_connect
(
PySocketSockObject
*
s
,
PyObject
*
a
ddro
)
{
struct
sockaddr
*
addr
;
int
addrlen
;
int
res
;
PyObject
*
addro
;
if
(
!
PyArg_ParseTuple
(
args
,
"O:connect"
,
&
addro
))
return
NULL
;
if
(
!
getsockaddrarg
(
s
,
addro
,
&
addr
,
&
addrlen
))
return
NULL
;
Py_BEGIN_ALLOW_THREADS
...
...
@@ -1243,14 +1237,12 @@ is a pair (host, port).";
/* s.connect_ex(sockaddr) method */
static
PyObject
*
PySocketSock_connect_ex
(
PySocketSockObject
*
s
,
PyObject
*
a
rgs
)
PySocketSock_connect_ex
(
PySocketSockObject
*
s
,
PyObject
*
a
ddro
)
{
struct
sockaddr
*
addr
;
int
addrlen
;
int
res
;
PyObject
*
addro
;
if
(
!
PyArg_ParseTuple
(
args
,
"O:connect_ex"
,
&
addro
))
return
NULL
;
if
(
!
getsockaddrarg
(
s
,
addro
,
&
addr
,
&
addrlen
))
return
NULL
;
Py_BEGIN_ALLOW_THREADS
...
...
@@ -1271,10 +1263,8 @@ instead of raising an exception when an error occurs.";
/* s.fileno() method */
static
PyObject
*
PySocketSock_fileno
(
PySocketSockObject
*
s
,
PyObject
*
args
)
PySocketSock_fileno
(
PySocketSockObject
*
s
)
{
if
(
!
PyArg_ParseTuple
(
args
,
":fileno"
))
return
NULL
;
#if SIZEOF_SOCKET_T <= SIZEOF_LONG
return
PyInt_FromLong
((
long
)
s
->
sock_fd
);
#else
...
...
@@ -1292,12 +1282,11 @@ Return the integer file descriptor of the socket.";
/* s.dup() method */
static
PyObject
*
PySocketSock_dup
(
PySocketSockObject
*
s
,
PyObject
*
args
)
PySocketSock_dup
(
PySocketSockObject
*
s
)
{
SOCKET_T
newfd
;
PyObject
*
sock
;
if
(
!
PyArg_ParseTuple
(
args
,
":dup"
))
return
NULL
;
newfd
=
dup
(
s
->
sock_fd
);
if
(
newfd
<
0
)
return
PySocket_Err
();
...
...
@@ -1321,14 +1310,12 @@ Return a new socket object connected to the same system resource.";
/* s.getsockname() method */
static
PyObject
*
PySocketSock_getsockname
(
PySocketSockObject
*
s
,
PyObject
*
args
)
PySocketSock_getsockname
(
PySocketSockObject
*
s
)
{
char
addrbuf
[
256
];
int
res
;
socklen_t
addrlen
;
if
(
!
PyArg_ParseTuple
(
args
,
":getsockname"
))
return
NULL
;
if
(
!
getsockaddrlen
(
s
,
&
addrlen
))
return
NULL
;
memset
(
addrbuf
,
0
,
addrlen
);
...
...
@@ -1351,14 +1338,12 @@ info is a pair (hostaddr, port).";
/* s.getpeername() method */
static
PyObject
*
PySocketSock_getpeername
(
PySocketSockObject
*
s
,
PyObject
*
args
)
PySocketSock_getpeername
(
PySocketSockObject
*
s
)
{
char
addrbuf
[
256
];
int
res
;
socklen_t
addrlen
;
if
(
!
PyArg_ParseTuple
(
args
,
":getpeername"
))
return
NULL
;
if
(
!
getsockaddrlen
(
s
,
&
addrlen
))
return
NULL
;
memset
(
addrbuf
,
0
,
addrlen
);
...
...
@@ -1382,11 +1367,13 @@ info is a pair (hostaddr, port).";
/* s.listen(n) method */
static
PyObject
*
PySocketSock_listen
(
PySocketSockObject
*
s
,
PyObject
*
arg
s
)
PySocketSock_listen
(
PySocketSockObject
*
s
,
PyObject
*
arg
)
{
int
backlog
;
int
res
;
if
(
!
PyArg_ParseTuple
(
args
,
"i:listen"
,
&
backlog
))
backlog
=
PyInt_AsLong
(
arg
);
if
(
backlog
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
Py_BEGIN_ALLOW_THREADS
if
(
backlog
<
1
)
...
...
@@ -1606,11 +1593,13 @@ For IP sockets, the address is a pair (hostaddr, port).";
/* s.shutdown(how) method */
static
PyObject
*
PySocketSock_shutdown
(
PySocketSockObject
*
s
,
PyObject
*
arg
s
)
PySocketSock_shutdown
(
PySocketSockObject
*
s
,
PyObject
*
arg
)
{
int
how
;
int
res
;
if
(
!
PyArg_ParseTuple
(
args
,
"i:shutdown"
,
&
how
))
how
=
PyInt_AsLong
(
arg
);
if
(
how
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
Py_BEGIN_ALLOW_THREADS
res
=
shutdown
(
s
->
sock_fd
,
how
);
...
...
@@ -1631,31 +1620,31 @@ of the socket (flag == 1), or both ends (flag == 2).";
/* List of methods for socket objects */
static
PyMethodDef
PySocketSock_methods
[]
=
{
{
"accept"
,
(
Py
CFunction
)
PySocketSock_accept
,
METH_VAR
ARGS
,
{
"accept"
,
(
Py
NoArgsFunction
)
PySocketSock_accept
,
METH_NO
ARGS
,
accept_doc
},
{
"bind"
,
(
PyCFunction
)
PySocketSock_bind
,
METH_
VARARGS
,
{
"bind"
,
(
PyCFunction
)
PySocketSock_bind
,
METH_
O
,
bind_doc
},
{
"close"
,
(
Py
CFunction
)
PySocketSock_close
,
METH_VAR
ARGS
,
{
"close"
,
(
Py
NoArgsFunction
)
PySocketSock_close
,
METH_NO
ARGS
,
close_doc
},
{
"connect"
,
(
PyCFunction
)
PySocketSock_connect
,
METH_
VARARGS
,
{
"connect"
,
(
PyCFunction
)
PySocketSock_connect
,
METH_
O
,
connect_doc
},
{
"connect_ex"
,
(
PyCFunction
)
PySocketSock_connect_ex
,
METH_
VARARGS
,
{
"connect_ex"
,
(
PyCFunction
)
PySocketSock_connect_ex
,
METH_
O
,
connect_ex_doc
},
#ifndef NO_DUP
{
"dup"
,
(
Py
CFunction
)
PySocketSock_dup
,
METH_VAR
ARGS
,
{
"dup"
,
(
Py
NoArgsFunction
)
PySocketSock_dup
,
METH_NO
ARGS
,
dup_doc
},
#endif
{
"fileno"
,
(
Py
CFunction
)
PySocketSock_fileno
,
METH_VAR
ARGS
,
{
"fileno"
,
(
Py
NoArgsFunction
)
PySocketSock_fileno
,
METH_NO
ARGS
,
fileno_doc
},
#ifdef HAVE_GETPEERNAME
{
"getpeername"
,
(
Py
CFunction
)
PySocketSock_getpeername
,
METH_VARARGS
,
getpeername_doc
},
{
"getpeername"
,
(
Py
NoArgsFunction
)
PySocketSock_getpeername
,
METH_NOARGS
,
getpeername_doc
},
#endif
{
"getsockname"
,
(
Py
CFunction
)
PySocketSock_getsockname
,
METH_VARARGS
,
getsockname_doc
},
{
"getsockname"
,
(
Py
NoArgsFunction
)
PySocketSock_getsockname
,
METH_NOARGS
,
getsockname_doc
},
{
"getsockopt"
,
(
PyCFunction
)
PySocketSock_getsockopt
,
METH_VARARGS
,
getsockopt_doc
},
{
"listen"
,
(
PyCFunction
)
PySocketSock_listen
,
METH_
VARARGS
,
{
"listen"
,
(
PyCFunction
)
PySocketSock_listen
,
METH_
O
,
listen_doc
},
#ifndef NO_DUP
{
"makefile"
,
(
PyCFunction
)
PySocketSock_makefile
,
METH_VARARGS
,
...
...
@@ -1669,11 +1658,11 @@ static PyMethodDef PySocketSock_methods[] = {
send_doc
},
{
"sendto"
,
(
PyCFunction
)
PySocketSock_sendto
,
METH_VARARGS
,
sendto_doc
},
{
"setblocking"
,
(
PyCFunction
)
PySocketSock_setblocking
,
METH_
VARARGS
,
{
"setblocking"
,
(
PyCFunction
)
PySocketSock_setblocking
,
METH_
O
,
setblocking_doc
},
{
"setsockopt"
,
(
PyCFunction
)
PySocketSock_setsockopt
,
METH_VARARGS
,
setsockopt_doc
},
{
"shutdown"
,
(
PyCFunction
)
PySocketSock_shutdown
,
METH_
VARARGS
,
{
"shutdown"
,
(
PyCFunction
)
PySocketSock_shutdown
,
METH_
O
,
shutdown_doc
},
#ifdef RISCOS
{
"sleeptaskw"
,
(
PyCFunction
)
PySocketSock_sleeptaskw
,
METH_VARARGS
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment