Article View: borland.public.cppbuilder.nativeapi
Article #8963Re: creating a non-blocking socket with WinSock?
From: Remy Lebeau (TeamB)
Date: Mon, 23 Aug 2004 16:53
Date: Mon, 23 Aug 2004 16:53
32 lines
2221 bytes
2221 bytes
"Robert G. Hoover" <not.a.real.address@anywhere.sorry> wrote in message news:4129eac9@newsgroups.borland.com... > How can I create a non-blocking socket with windows sockets? > I've been crawling thought the documentation but haven't found > a place to specify the non-blocking vs thread-blocking which > corresponds to TServerSocket:::ServerType. Use ioctlsocket() with the FIONBIO option. > So, when I call accept, my thread is suspended, waiting for a > client to connect. If no client tries to connect, then when I exit > the program, the thread is still active. Do the listening in its own thread, and then having the thread that wants to exit the program just close the server socket directly. The blocked accept() in the listening thread will exit with an error and the listening thread can then terminate in a timely fashion. > If I can set my socket to non-blocking, then accept() will return > an error is no client is trying to connect and my thread will be > allowed to loop/exit, right? You could always call select() before calling accept(). You can specify a timeout value for select(), and select() will tell you if a client is waiting on a listening socket or not, thus you can call accept() only when a client is actually trying to connect and thus accept() will not block at all. Gambit
Technical Details
Message-ID:
<412a20da$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4129eac9@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a7377a39e2ca7927 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4129eac9@newsgroups.borland.com> Subject: Re: creating a non-blocking socket with WinSock? Date: Mon, 23 Aug 2004 09:53:57 -0700 Lines: 34 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <412a20da$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1093279962 68.69.17.41 (23 Aug 2004 09:52:42 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail