Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8119447f
Kaydet (Commit)
8119447f
authored
Tem 27, 1991
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add gethostname() and s.avail().
üst
e0d452d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
3 deletions
+52
-3
socketmodule.c
Modules/socketmodule.c
+52
-3
No files found.
Modules/socketmodule.c
Dosyayı görüntüle @
8119447f
...
...
@@ -30,13 +30,14 @@ This module provides an interface to Berkeley socket IPC.
Limitations:
- only AF_INET and AF_UNIX address families are supported
- no asynchronous I/O
- no read/write operations (use send/recv instead)
- no asynchronous I/O
(but read polling: avail)
- no read/write operations (use send/recv
or makefile
instead)
- no flags on sendto/recvfrom operations
- no setsockopt() call
Interface:
- socket.gethostname() --> host name (string)
- socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd')
- socket.getservbyname(servername, protocolname) --> port number
- socket.socket(family, type [, proto]) --> new socket object
...
...
@@ -50,9 +51,10 @@ Interface:
Socket methods:
- s.accept() --> new socket object, sockaddr
- s.avail() --> boolean
- s.bind(sockaddr) --> None
- s.connect(sockaddr) --> None
- s.accept() --> new socket object, sockaddr
- s.listen(n) --> None
- s.makefile(mode) --> file object
- s.recv(nbytes) --> string
...
...
@@ -67,11 +69,16 @@ Socket methods:
#include "allobjects.h"
#include "modsupport.h"
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
/* Needed for struct timeval */
#include <netinet/in.h>
#include <sys/un.h>
#include <netdb.h>
#ifdef _AIX
/* I *think* this works */
#include <select.h>
/* Needed for fd_set */
#endif
/* Global variable holding the exception type for errors detected
...
...
@@ -336,6 +343,27 @@ sock_accept(s, args)
}
/* s.avail() method */
static
object
*
sock_avail
(
s
,
args
)
sockobject
*
s
;
object
*
args
;
{
struct
timeval
timeout
;
fd_set
readers
;
int
n
;
timeout
.
tv_sec
=
0
;
timeout
.
tv_usec
=
0
;
FD_ZERO
(
&
readers
);
FD_SET
(
s
->
sock_fd
,
&
readers
);
n
=
select
(
s
->
sock_fd
+
1
,
&
readers
,
(
fd_set
*
)
0
,
(
fd_set
*
)
0
,
&
timeout
);
if
(
n
<
0
)
return
socket_error
();
return
newintobject
((
long
)
(
n
!=
0
));
}
/* s.bind(sockaddr) method */
static
object
*
...
...
@@ -555,6 +583,7 @@ sock_shutdown(s, args)
static
struct
methodlist
sock_methods
[]
=
{
{
"accept"
,
sock_accept
},
{
"avail"
,
sock_avail
},
{
"bind"
,
sock_bind
},
{
"close"
,
sock_close
},
{
"connect"
,
sock_connect
},
...
...
@@ -614,6 +643,22 @@ static typeobject Socktype = {
};
/* Python interface to gethostname(). */
/*ARGSUSED*/
static
object
*
socket_gethostname
(
self
,
args
)
object
*
self
;
object
*
args
;
{
char
buf
[
1024
];
if
(
!
getnoarg
(
args
))
return
NULL
;
if
(
gethostname
(
buf
,
sizeof
buf
-
1
)
<
0
)
return
socket_error
();
buf
[
sizeof
buf
-
1
]
=
'\0'
;
return
newstringobject
(
buf
);
}
/* Python interface to gethostbyname(name). */
/*ARGSUSED*/
...
...
@@ -685,6 +730,9 @@ socket_socket(self, args)
file descriptor again! */
if
(
s
==
NULL
)
(
void
)
close
(
fd
);
/* From now on, ignore SIGPIPE and let the error checking
do the work. */
(
void
)
signal
(
SIGPIPE
,
SIG_IGN
);
return
(
object
*
)
s
;
}
...
...
@@ -693,6 +741,7 @@ socket_socket(self, args)
static
struct
methodlist
socket_methods
[]
=
{
{
"gethostbyname"
,
socket_gethostbyname
},
{
"gethostname"
,
socket_gethostname
},
{
"getservbyname"
,
socket_getservbyname
},
{
"socket"
,
socket_socket
},
{
NULL
,
NULL
}
/* Sentinel */
...
...
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