Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NODELAY socket from python?

737 views
Skip to first unread message

Rob Hooft

unread,
May 27, 1998, 3:00:00 AM5/27/98
to

Currently, my code contains the following line:

s.setsockopt(6,1,1) #socket.IPPROTO_TCP,socket.TCP_NODELAY,TRUE

The comment points to two non-existing symbols in the socket module.
I'm not sure whether this really makes the socket a NODELAY socket (am
having some undefinable communications problems), and furthermore I
refuse to assume that this is portable to other architectures than
Linux.

Is there a proper way of making a socket NODELAY from python?

--
== R.H...@EuroMail.com http://www.Sander.EMBL-Heidelberg.DE/rob/ ==
== R&D, Nonius BV, Delft http://www.nonius.com/ ==
= PGPid 0xFA19277D ====================== Use Linux! ==================

Rob Hooft

unread,
May 28, 1998, 3:00:00 AM5/28/98
to

>>>>> "AK" == Andrew Kuchling <akuc...@cnri.reston.va.us> writes:

AK> Rob Hooft writes:
>> s.setsockopt(6,1,1) #socket.IPPROTO_TCP,socket.TCP_NODELAY,TRUE
>>
>> The comment points to two non-existing symbols in the socket
>> module.

AK> In 1.5.1, at least, IPPROTO_TCP should be there; there's an
AK> ifdef for it in Modules/socketmodule.c.

devel[596]nonius%% python
Python 1.5.1 (#3, May 6 1998, 17:13:12) [GCC pgcc-2.90.21 971202 (egc on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import socket
>>> socket.IPPROTO_TCP
Traceback (innermost last):
File "<stdin>", line 1, in ?
AttributeError: IPPROTO_TCP

AK> (Ugh... I just realized, what if IPPROTO_TCP is defined as an
AK> enum, and not a preprocessor macro?)

/* Standard well-defined IP protocols. */
enum {
IPPROTO_IP = 0, /* Dummy protocol for TCP */
IPPROTO_ICMP = 1, /* Internet Control Message Protocol */
IPPROTO_IGMP = 2, /* Internet Group Management Protocol */
IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94) */
IPPROTO_TCP = 6, /* Transmission Control Protocol */
IPPROTO_EGP = 8, /* Exterior Gateway Protocol */
IPPROTO_PUP = 12, /* PUP protocol */
IPPROTO_UDP = 17, /* User Datagram Protocol */
IPPROTO_IDP = 22, /* XNS IDP protocol */

IPPROTO_RAW = 255, /* Raw IP packets */
IPPROTO_MAX
};

AK> You might try running Tools/scripts/h2py.py on the
AK> relevant .h files, too.

The fun job is to figure out which .h files are the relevant ones on
each supported machine.... I'll try this.

Thanks very much for the hints!

--
===== R.H...@EuroMail.com http://www.Sander.EMBL-Heidelberg.DE/rob/ ==
===== R&D, Nonius BV, Delft http://www.nonius.com/ ==
===== PGPid 0xFA19277D ========================== Use Linux! ==================

Guido van Rossum

unread,
May 28, 1998, 3:00:00 AM5/28/98
to

> From: R.H...@EuroMail.com (Rob Hooft)

> >> s.setsockopt(6,1,1) #socket.IPPROTO_TCP,socket.TCP_NODELAY,TRUE
> >>
> >> The comment points to two non-existing symbols in the socket
> >> module.

You've already found out the reason that IPPROTO_TCP is undefined for
you: the socketmodule.c code guards its definition with #ifdef
IPPROTO_TCP, which is inappropriate because Linux uses an enum. The
patch below should fix this for a small number of important symbols.

Regarding TCP_NODELAY -- are you sure this is the option you want?
The tcp(7) man page on Solaris 2.6 has this:

Under most circumstances, TCP sends data when it is
presented. When outstanding data has not yet been ack-
nowledged, TCP gathers small amounts of output to be sent in
a single packet once an acknowledgement has been received.
For a small number of clients, such as window systems that
send a stream of mouse events which receive no replies, this
packetization may cause significant delays. To circumvent
this problem, TCP provides a socket-level boolean option,
TCP_NODELAY. TCP_NODELAY is defined in <netinet/tcp.h>, and
is set with setsockopt(3N) and tested with getsockopt(3N).
The option level for the setsockopt() call is the protocol
number for TCP, available from getprotobyname(3N).

Currently the socket module doesn't define any of the TCP_* symbols; I
haven't been able to find documentation on any of the others so I
thingk they are fairly obscure... Also I don't know how portable they
are.

--Guido van Rossum (home page: http://www.python.org/~guido/)

Index: socketmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.71
diff -c -r1.71 socketmodule.c
*** socketmodule.c 1998/04/09 20:56:35 1.71
--- socketmodule.c 1998/05/28 18:38:55
***************
*** 1668,1681 ****
--- 1668,1686 ----
#endif

/* Protocol level and numbers, usable for [gs]etsockopt */
+ /* Sigh -- some systems (e.g. Linux) use enums for these. */
#ifdef SOL_SOCKET
insint(d, "SOL_SOCKET", SOL_SOCKET);
#endif
#ifdef IPPROTO_IP
insint(d, "IPPROTO_IP", IPPROTO_IP);
+ #else
+ insint(d, "IPPROTO_IP", 0);
#endif
#ifdef IPPROTO_ICMP
insint(d, "IPPROTO_ICMP", IPPROTO_ICMP);
+ #else
+ insint(d, "IPPROTO_ICMP", 1);
#endif
#ifdef IPPROTO_IGMP
insint(d, "IPPROTO_IGMP", IPPROTO_IGMP);
***************
*** 1685,1690 ****
--- 1690,1697 ----
#endif
#ifdef IPPROTO_TCP
insint(d, "IPPROTO_TCP", IPPROTO_TCP);
+ #else
+ insint(d, "IPPROTO_TCP", 6);
#endif
#ifdef IPPROTO_EGP
insint(d, "IPPROTO_EGP", IPPROTO_EGP);
***************
*** 1694,1699 ****
--- 1701,1708 ----
#endif
#ifdef IPPROTO_UDP
insint(d, "IPPROTO_UDP", IPPROTO_UDP);
+ #else
+ insint(d, "IPPROTO_UDP", 17);
#endif
#ifdef IPPROTO_IDP
insint(d, "IPPROTO_IDP", IPPROTO_IDP);
***************
*** 1719,1724 ****
--- 1728,1735 ----
/**/
#ifdef IPPROTO_RAW
insint(d, "IPPROTO_RAW", IPPROTO_RAW);
+ #else
+ insint(d, "IPPROTO_RAW", 255);
#endif
#ifdef IPPROTO_MAX
insint(d, "IPPROTO_MAX", IPPROTO_MAX);

Rob Hooft

unread,
Jun 2, 1998, 3:00:00 AM6/2/98
to

>>>>> "GvR" == Guido van Rossum <gu...@CNRI.Reston.Va.US> writes:

GvR> You've already found out the reason that IPPROTO_TCP is
GvR> undefined for you: the socketmodule.c code guards its definition
GvR> with #ifdef IPPROTO_TCP, which is inappropriate because Linux
GvR> uses an enum. The patch below should fix this for a small
GvR> number of important symbols.

Thanks. I was also told to try h2py.py, but it also fails to register
enum {}.

GvR> Regarding TCP_NODELAY -- are you sure this is the option you
GvR> want? The tcp(7) man page on Solaris 2.6 has this:

I'm sure this is the option I want, but after reading your man-page
extract I am no longer sure I need it. I am using a strange protocol
to communicate with a robot, so I'm not surprised to find that I could
be using options that are not very well known.

GvR> Under most circumstances, TCP sends data when it is
GvR> presented. When outstanding data has not yet been ack-
GvR> nowledged, TCP gathers small amounts of output to be sent in a
GvR> single packet once an acknowledgement has been received.

The key is the "outstanding data" that has not been acknowledged. I'm
not sure what is meant by this. I am afraid this could mean some of my
data will be delayed more than necessary.

Regards,

0 new messages