david-maw / StreamSSL

The StreamSSL sample described in CodeProject
Other
47 stars 24 forks source link

CActiveSock::Disconnect should return ERROR_SUCCESS / S_OK #58

Closed 0ric1 closed 5 years ago

0ric1 commented 5 years ago

when ActualSocket == INVALID_SOCKET

david-maw commented 5 years ago

That's a bit of a tricky one - should calling Disconnect on a disconnected socket be an error or not? Calling Disconnect twice is probably an error but the caller can choose to ignore it if they want to, so is it better to return an error that can be ignored, perhaps flagging a logic error, or silently do nothing? There may be a compelling argument by analogy with destructors or, more likely, Dispose where Microsoft write "If an object's Dispose method is called more than once, the object must ignore all calls after the first one. The object must not throw an exception if its Dispose method is called multiple times." On the other hand you can't call, say WSACloseEvent twice on the same event. I lean slightly toward agreeing with your suggestion, but it's perhaps woth a little thought before making the change.

Did any of this change your mind, or do you still think it should return S_OK in this case?

0ric1 commented 5 years ago

I think it's not an error to Close/Disconnet/free/delete more than once and in this case it should return S_OK.

david-maw commented 5 years ago

Well, it's an error to close the same handle or free the same memory twice, but I agree closing a file twice should be ok so I changed it.