• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[Newbie] Strange accept() with ab behaviour
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Newbie] Strange accept() with ab behaviour


  • Subject: [Newbie] Strange accept() with ab behaviour
  • From: Andrea -XFox- Govoni <email@hidden>
  • Date: Fri, 16 Jul 2004 02:43:27 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,
sorry for the newbie question but I really can't understand this.
I'm on Mac OS X 10.3.4 and I'm working with BSD sockets.
I noticed a strange (for me) behaviour of the accept() system call
tested with ApacheBench, Version 1.3d (the default ApacheBench installed
with Phanter).
This is my simple test case:

<begin-code-here>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main(int argc, char *argv[]) {
int listen_socket, com_socket, dim;
struct sockaddr_in a_socket, b_socket;
dim = sizeof(struct sockaddr);
a_socket.sin_family = AF_INET;
a_socket.sin_port = htons(2000);
a_socket.sin_addr.s_addr = INADDR_ANY;
bzero(&(a_socket.sin_zero), 8);
listen_socket = socket(AF_INET, SOCK_STREAM, 0);
if(bind(listen_socket, (struct sockaddr *)&a_socket, dim) == -1) {
puts("\nBIND() ERROR\n");
return -1;
}
listen(listen_socket, 10);
while(1) {
com_socket = accept(listen_socket, (struct sockaddr *)&b_socket, &dim);
puts("I'm in.");
close(com_socket);
}
return 0;
}
<end-code-here>

I read in the man page that accept() is blocking by default, that is, if
there aren't clients in the listen socket queue it should stop and wait
for a client.
If I start the server, open iCab 2.9.8 and type "http://127.0.0.1:2000/";
in the address line it works as expected (it prints "I'm in." to the
standard output only one time).
Conversely, if I test my server with ApacheBench with the command "ab
http://127.0.0.1:2000/"; (that should send only one request), I got two
prints of "I'm in.".
My simple question is: why?
I need to test my rough web server with ApacheBench, so I need to solve
this.
Thanks in advance,

- --
Andrea "XFox" Govoni
ICQ UIN: 43488185
AIM/iChat: email@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
Comment: Using GnuPG with Netscape - http://enigmail.mozdev.org

iD8DBQFA9ySut6BgXyEuacERAliuAKCJCbFbEWlUfJtWijKe80Qa/hvS2ACghqmF
pPRRQp2CKaB41XqjcuP0EoY=
=LFpS
-----END PGP SIGNATURE-----
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: Newbie Question
  • Next by Date: Admin: Bouncing Emails and Digest Mode
  • Previous by thread: Re: Newbie Question follow up
  • Next by thread: Admin: Bouncing Emails and Digest Mode
  • Index(es):
    • Date
    • Thread