canceling BeginRead by closing socket - is it OK ?

  • Thread starter Thread starter Shane
  • Start date Start date
S

Shane

I want to use BeginRead on a socket stream. I want to abort the read if no
data arrives within a certain time interval. I know i can't cancell the
BeginRead directly but closing the socket seems to work. Does this cause any
problems (Resource leaks etc) ?

Should I also call EndRead after closing the socket even though it will it
throw ? Has anyone done anything similar ?



Shane
 
Yes, you can close the socket, which will cancel all outstanding I/O. Your
callback will still be signalled, and EndRead will throw an exception, which
you have to handle.
 
Back
Top