writev() bug? linux 2.0.32, gcc2.7.2.3-5, libc-5.4.38-1...

Christoph Moar (christoph.moar@mchp.siemens.de)
Fri, 21 Nov 1997 10:43:48 +0100


Hi people,

excuse me if this is the wrong place to ask, but I
tried a couple newsgroups and noone could help me
out, instead they pointed me to this mailing list.
I am not a recipient of this list (although I might,
if needed), so pleas CC: to my email adress if
you reply. Thanks.

I have a nasty bug which nearly drives me crazy:
could someone be so kind to try to reproduce this
bug or at least tell me if its known or what I
am doing wrong?

The little test program uses writev() on a socket,
in this case just the loopback address, 127.0.0.1,
it doesn't really matter what ip address we use.
It doesn't matter if only one or more iovec's are
written, in this case just one, or if write() is
used instead.

So, what happens:
the first writev() works, the second doesn't, the
third one does, the fourth doesn't again...

the output looks like this:
main() ok
main() writev() failed: errno 111 Connection refused (status -1)
main() ok
main() writev() failed: errno 111 Connection refused (status -1)
main() ok
main() writev() failed: errno 111 Connection refused (status -1)

on other systems (solaris, sgi, relaint unix etc...) the whole
thing just works fine, I just don't get it. The whole system
is a out-of-the-box Red Hat 4.2 with some enhancements that
I needed along the way. I had the error with 2.0.30-2 and
updated to 2.0.32, also with gcc-2.7.2.3-5 which I had to
upgrade to the egcs snapshot for the better template support.
I also hat binutils-2.8.1.0.1-1 and upgraded to binutils
2.8.1.0.15.

my configuration:
kernel-2.0.32
gcc-2.7.2.3-5
[also egcs-2.90.17 971114 (gcc2-970802 experimental)]
libc-5.4.38-1
libg++-2.7.2.8-1
binutils-2.8.1.0.15

--- snip ---
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <iostream.h>
#include <string.h>
#include <errno.h>
#include <sys/uio.h>

void main(void) {

// locals
char* aInetAddr = "127.0.0.1";
char* clientString;
int aPort = 2864;
int sock;

char* buffer[4096];
char* me = "main()";

// open the socket
if ((sock = socket (AF_INET, SOCK_DGRAM, 0)) <0) {
cerr << me << ": socket() call failed" << endl;
}

// set up the destination address
struct sockaddr_in sin;
struct hostent* hp;
char** p;

// try to get the ip address
hp = gethostbyname (aInetAddr);
if (hp == NULL) {
cerr << me << ": gethostbyname("<< aInetAddr << ") failed" << endl;
}

// convert to ip notation
for (p = hp->h_addr_list; *p != 0; p++) {
struct in_addr in;
memcpy(&in.s_addr, *p, sizeof (in.s_addr));
clientString = inet_ntoa(in);
break;
}

memset ((char *)&sin, 0, sizeof(sin));
memcpy ((char *)&sin.sin_addr, hp->h_addr, hp->h_length);

sin.sin_family = AF_INET;
sin.sin_port = aPort;

if (connect (sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
cerr << me << ": connect(" << clientString << ':' << aPort << "): "
<< strerror(errno) << endl;
}

cout << me << ": connect() to " << clientString << endl;

int status;
int length;

// sum up the length
length = 4096;

struct iovec iov[1]; // iovec struct of byte buffer
int iovcnt; // iovec count {1}

iov[0].iov_base = (caddr_t) buffer;
iov[0].iov_len = length;
iovcnt = 1;

// send the payload
for (int i=0; i<20; i++) {
if ((status = writev (sock, iov, iovcnt)) != length)
cerr << me << " writev() failed: errno " << errno << ' ' <<
strerror(errno)
<< " (status " << status << ")" << endl;
else
cout << me << " ok" << endl;
sleep(1);
}

}

--- snap ---

best regards,

Christoph.

--
Christoph Moar (christoph.moar@mchp.siemens.de)  Tel. (++49) 89 636-44628
SIEMENS AG Corporate Technology                  Fax. (++49) 89 636-47457
Information and Media Technology
Office Adress:  SIEMENS AG  ZT IK 1,  Otto-Hahn-Ring  6,  D-81739  Munich
Postal Adress:  SIEMENS AG  ZT IK 1,  D-81730 Munich
***   PGP PUBLIC KEY AVAILABLE ON REQUEST & ON KEY SERVERS WORLDWIDE  ***