Mercurial > cpython-lru_cache-weakref
comparison Modules/socketmodule.c @ 396:c262f421a44c legacy-trunk
Added allowbroadcast()
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 20 Oct 1991 20:22:28 +0000 |
| parents | 70a18a6689d4 |
| children | a5f0b8390c87 |
comparison
equal
deleted
inserted
replaced
| 395:659b8dbf695c | 396:c262f421a44c |
|---|---|
| 31 | 31 |
| 32 - only AF_INET and AF_UNIX address families are supported | 32 - only AF_INET and AF_UNIX address families are supported |
| 33 - no asynchronous I/O (but read polling: avail) | 33 - no asynchronous I/O (but read polling: avail) |
| 34 - no read/write operations (use send/recv or makefile instead) | 34 - no read/write operations (use send/recv or makefile instead) |
| 35 - no flags on sendto/recvfrom operations | 35 - no flags on sendto/recvfrom operations |
| 36 - no setsockopt() call | 36 - no general setsockopt() call (but see s.allowbroadcast()) |
| 37 | 37 |
| 38 Interface: | 38 Interface: |
| 39 | 39 |
| 40 - socket.gethostname() --> host name (string) | 40 - socket.gethostname() --> host name (string) |
| 41 - socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd') | 41 - socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd') |
| 51 | 51 |
| 52 Socket methods: | 52 Socket methods: |
| 53 | 53 |
| 54 - s.accept() --> new socket object, sockaddr | 54 - s.accept() --> new socket object, sockaddr |
| 55 - s.avail() --> boolean | 55 - s.avail() --> boolean |
| 56 - s.allowbroadcast(boolean) --> None | |
| 56 - s.bind(sockaddr) --> None | 57 - s.bind(sockaddr) --> None |
| 57 - s.connect(sockaddr) --> None | 58 - s.connect(sockaddr) --> None |
| 58 - s.listen(n) --> None | 59 - s.listen(n) --> None |
| 59 - s.makefile(mode) --> file object | 60 - s.makefile(mode) --> file object |
| 60 - s.recv(nbytes) --> string | 61 - s.recv(nbytes) --> string |
| 339 close(newfd); | 340 close(newfd); |
| 340 return res; | 341 return res; |
| 341 } | 342 } |
| 342 | 343 |
| 343 | 344 |
| 345 /* s.allowbroadcast() method */ | |
| 346 | |
| 347 static object * | |
| 348 sock_allowbroadcast(s, args) | |
| 349 sockobject *s; | |
| 350 object *args; | |
| 351 { | |
| 352 int flag; | |
| 353 int res; | |
| 354 if (!getintarg(args, &flag)) | |
| 355 return NULL; | |
| 356 res = setsockopt(s->sock_fd, SOL_SOCKET, SO_BROADCAST, | |
| 357 &flag, sizeof flag); | |
| 358 if (res < 0) | |
| 359 return socket_error(); | |
| 360 INCREF(None); | |
| 361 return None; | |
| 362 } | |
| 363 | |
| 364 | |
| 344 /* s.avail() method */ | 365 /* s.avail() method */ |
| 345 | 366 |
| 346 static object * | 367 static object * |
| 347 sock_avail(s, args) | 368 sock_avail(s, args) |
| 348 sockobject *s; | 369 sockobject *s; |
| 580 /* List of methods for socket objects */ | 601 /* List of methods for socket objects */ |
| 581 | 602 |
| 582 static struct methodlist sock_methods[] = { | 603 static struct methodlist sock_methods[] = { |
| 583 {"accept", sock_accept}, | 604 {"accept", sock_accept}, |
| 584 {"avail", sock_avail}, | 605 {"avail", sock_avail}, |
| 606 {"allowbroadcast", sock_allowbroadcast}, | |
| 585 {"bind", sock_bind}, | 607 {"bind", sock_bind}, |
| 586 {"close", sock_close}, | 608 {"close", sock_close}, |
| 587 {"connect", sock_connect}, | 609 {"connect", sock_connect}, |
| 588 {"listen", sock_listen}, | 610 {"listen", sock_listen}, |
| 589 {"makefile", sock_makefile}, | 611 {"makefile", sock_makefile}, |
