Click here to Skip to main content
15,890,557 members
Home / Discussions / C#
   

C#

 
AnswerRe: Closing sockets in asynchronous TCP server Pin
Nicholas Butler8-Nov-08 1:01
sitebuilderNicholas Butler8-Nov-08 1:01 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Metal768-Nov-08 1:10
Metal768-Nov-08 1:10 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Nicholas Butler8-Nov-08 2:39
sitebuilderNicholas Butler8-Nov-08 2:39 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Metal768-Nov-08 23:16
Metal768-Nov-08 23:16 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Nicholas Butler9-Nov-08 3:41
sitebuilderNicholas Butler9-Nov-08 3:41 
AnswerRe: Closing sockets in asynchronous TCP server Pin
Mark Salsbery9-Nov-08 7:46
Mark Salsbery9-Nov-08 7:46 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Metal769-Nov-08 9:09
Metal769-Nov-08 9:09 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Mark Salsbery9-Nov-08 9:43
Mark Salsbery9-Nov-08 9:43 
Metal76 wrote:
I feel a little uneasy to use exceptions to implement normal programming logic, but I could not find a "clean" way to forcibly shutdown sockets


Hi Andrea,

I'd love to find a cleaner method, but I haven't, which is why I do
it that way Smile | :) I do include comments in my callback delegate code
to remind me that certain exceptions are expected during shutdown.

My server code was ported from C++, where I used an IO completion port.
The same problem existed there, except the function used by the completion handler
threads to wait for a completed IO (GetQueuedCompletionStatus) would indicate an error
instead of throwing an exception. I still used the queuedIOcount there, because I wanted
to wait for all pending IOs to be flushed from the completion port at shutdown before
continuing.

I'm pretty sure .NET's asynchronous IO uses IO completion ports as well, or the equivalent.
The difference is, .NET handles the pool of threads for you where in straight Win32, one
has to handle that manually. From everything I've seen, they chose to implement the shutdown
as an exception instead of using an error code. I guess an error code could have been
added to the IAsyncResult, but it wouldn't have been generic - IAsyncResults are used for more
than just socket accepts and receives. Instead, the specific "Endxxxx" method documentation
specifies the exception that will be thrown in error conditions. For example,
Socket.EndReceive() states "ObjectDisposedException...The Socket has been closed".


I don't see an alternative. The whole idea of asynchronous IO is "fire-and-forget".
Once you call "Beginxxxx", the IO request is out of your hands until completion.
They chose to implement exceptions instead of error codes - you don't get anything else
to work with AFAIK Smile | :)

Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

QuestionCan i run windows application in Linux ? Pin
Krishnraj7-Nov-08 22:15
Krishnraj7-Nov-08 22:15 
AnswerRe: Can i run windows application in Linux ? Pin
Perspx7-Nov-08 22:33
Perspx7-Nov-08 22:33 
AnswerRe: Can i run windows application in Linux ? Pin
#realJSOP7-Nov-08 23:56
mve#realJSOP7-Nov-08 23:56 
GeneralRe: Can i run windows application in Linux ? Pin
Krishnraj1-Dec-08 1:46
Krishnraj1-Dec-08 1:46 
AnswerRe: Can i run windows application in Linux ? Pin
Dave Kreskowiak8-Nov-08 5:56
mveDave Kreskowiak8-Nov-08 5:56 
AnswerRe: Can i run windows application in Linux ? Pin
Atif Shahbaz8-Nov-08 6:11
Atif Shahbaz8-Nov-08 6:11 
AnswerRe: Can i run windows application in Linux ? Pin
Paul Conrad8-Nov-08 13:05
professionalPaul Conrad8-Nov-08 13:05 
QuestionAccess to soap WebServer without "Add Web Reference" Option Pin
Patricio Tapia7-Nov-08 22:01
Patricio Tapia7-Nov-08 22:01 
AnswerRe: Access to soap WebServer without "Add Web Reference" Option Pin
Wendelius8-Nov-08 1:05
mentorWendelius8-Nov-08 1:05 
QuestionBackgroundWorker and command line exe: what DoWork deals with? Pin
LordZoster7-Nov-08 20:52
LordZoster7-Nov-08 20:52 
AnswerRe: BackgroundWorker and command line exe: what DoWork deals with? Pin
#realJSOP7-Nov-08 23:58
mve#realJSOP7-Nov-08 23:58 
AnswerRe: BackgroundWorker and command line exe: what DoWork deals with? Pin
Giorgi Dalakishvili8-Nov-08 0:56
mentorGiorgi Dalakishvili8-Nov-08 0:56 
GeneralRe: BackgroundWorker and command line exe: what DoWork deals with? Pin
#realJSOP8-Nov-08 1:59
mve#realJSOP8-Nov-08 1:59 
GeneralRe: BackgroundWorker and command line exe: what DoWork deals with? Pin
LordZoster8-Nov-08 5:42
LordZoster8-Nov-08 5:42 
GeneralRe: BackgroundWorker and command line exe: what DoWork deals with? Pin
Dave Kreskowiak8-Nov-08 5:52
mveDave Kreskowiak8-Nov-08 5:52 
AnswerRe: BackgroundWorker and command line exe: what DoWork deals with? Pin
sph3rex8-Nov-08 5:46
sph3rex8-Nov-08 5:46 
AnswerRe: BackgroundWorker and command line exe: what DoWork deals with? Pin
Muammar©9-Nov-08 0:13
Muammar©9-Nov-08 0:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.