From: S A <sagarwal10@hotmail.com>
To: <cygwin@cygwin.com>
Subject: get_osfhandle & WaitForSingleObject on a cygwin socket fd....
Date: Fri, 21 Dec 2007 10:40:00 -0000 [thread overview]
Message-ID: <BAY128-W32F9825331F8E2EED0254BD25E0@phx.gbl> (raw)
Hi
Please bear with me if this is a stupid question but I'm trying to setup a telnet socket
in cygwin and then want to use a Windows wait semaphore (WaitForMultipleObjects)
to combine it with a sleep for winpcap HANDLEs.
I thought I'd test this first though.
Does get_osfhandle() on a AF_INET socket to the right thing? The WaitForSingleObject
below never wakes up (despite an incoming telnet connection).
Thanks.
main() {
struct sockaddr_in sin;
int s;
int opt = 1;
int ret;
HANDLE h;
/* init server socket. */
if ((s=socket(AF_INET, SOCK_STREAM, 0))< 0) {
printf("%s: setsockopt! %s\n", __FUNCTION__, strerror(errno));
}
/* try to bind to port */
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); // only bind to loopback now
sin.sin_port = htons(8081);
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
return LP_ERR_SOCKET;
}
if (listen(s, LEAD_PIPE_MAX_CONN) < 0) {
return LP_ERR_SOCKET;
}
h = (HANDLE) get_osfhandle(s);
ASSERT(h> 0);
fprintf(stdout, "Waiting on telnet handle %x\n", h);
while(1) {
WaitForSingleObject(h, INFINITE);
fprintf(stdout, "Awoke on telnet handle\n");
}
}
_________________________________________________________________
Don't get caught with egg on your face. Play Chicktionary!
http://club.live.com/chicktionary.aspx?icid=chick_wlhmtextlink1_dec
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
reply other threads:[~2007-12-21 2:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BAY128-W32F9825331F8E2EED0254BD25E0@phx.gbl \
--to=sagarwal10@hotmail.com \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).