CFSocket: register the socket type and fix datagram send and address queries#62
Open
DTW-Thalion wants to merge 1 commit into
Open
CFSocket: register the socket type and fix datagram send and address queries#62DTW-Thalion wants to merge 1 commit into
DTW-Thalion wants to merge 1 commit into
Conversation
CFSocketInitialize was never called from CFInitialize, so the CFSocket type was never registered and CFSocketCreateWithNative always returned NULL -- CFSocket was unusable. Register it, and fix the bugs that were hidden behind that: * CFSocketSendData passed length 0 (and the data length as the flags) to sendto(), so no data was transmitted; it also treated sendto()/send() return values as zero-on-success when they return the byte count, so the zero-length "send" was the only call that reported success. * CFSocketCopyPeerAddress read from and cached into the local-address field (_address) instead of _peerAddress. * CFSocketCopyAddress and CFSocketCopyPeerAddress called getsockname()/getpeername() with an uninitialised addrlen. Add Tests/CFSocket/general.m (loopback UDP send + address queries).
016eb25 to
250e8b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CFSocketInitializewas never called fromCFInitialize(it is missing fromboth the forward-declaration block and the call list), so the CFSocket type was
never registered:
_CFRuntimeCreateInstancerejected_kCFSocketTypeID == 0and
CFSocketCreateWithNativealways returned NULL. CFSocket was entirelyunusable. Registering it exposes three further bugs in the send/address code:
CFSocketSendDatapassed length0(and the data length as the flags)to
sendto(), so no data was transmitted. It also treatedsendto()/send()return values as zero-on-success, whereas they return the byte count — so the
zero-length "send" was the only call that ever reported success.
CFSocketCopyPeerAddressread from and cached into the local-addressfield (
_address) instead of_peerAddress.CFSocketCopyAddress/CFSocketCopyPeerAddresscalledgetsockname()/getpeername()with an uninitialisedaddrlen(avalue-result argument that must be set to the buffer size on entry).
Fix
Add
CFSocketInitialize()toCFInitialize; correct thesendto()argumentorder and success test; use
_peerAddress; initialiseaddrlen.Test
Tests/CFSocket/general.mwraps a native UDP socket in aCFSocket, sends adatagram over loopback and confirms it is received, and checks
CFSocketCopyAddress/CFSocketCopyPeerAddress. (All other corebase testsstill pass with the new type registered.)