Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want close a CFSocket

I have create a socket with CFSocket. My program is correct but now i wanna close the socket (client side). There 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
like image 804
zp26 Avatar asked May 18 '10 20:05

zp26


1 Answers

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
like image 189
Dave DeLong Avatar answered Oct 07 '22 15:10

Dave DeLong