开发者

I want close a CFSocket

开发者 https://www.devze.com 2022-12-31 10:54 出处:网络
I have create a socket with CFSocket. My program is correct but now i wanna close the socket (client side).

I have create a socket with CFSocket. My program is correct but now i wanna close the socket (client side). T开发者_StackOverflow社区here is a istruction? Thanks and sorry for my English XP

My code:

CFSocketRef s;
s = CFSocketCreate(
        NULL, 
        PF_INET,
        SOCK_STREAM, 
        IPPROTO_TCP, 
        kCFSocketDataCallBack, 
        AcceptDataCallback, 
        &context);
...
CFSocketConnectToAddress(s, address, 0);
...
//here i wanna close the socket


CFRelease(s) should close and destroy the socket.

edit (after a bit more research)

According to the documentation, the proper way to close the socket is by invalidating it (similar to how a Timer works, apparently). So you'll want to do:

CFSocketInvalidate(s);  //closes the socket, unless you set the option to not close on invalidation
CFRelease(s);  //balance the create
0

精彩评论

暂无评论...
验证码 换一张
取 消