---
title: "CFSocketInvalidate(_:)"
framework: corefoundation
role: symbol
role_heading: Function
path: "corefoundation/cfsocketinvalidate(_:)"
---

# CFSocketInvalidate(_:)

Invalidates a CFSocket object, stopping it from sending or receiving any more messages.

## Declaration

```swift
func CFSocketInvalidate(_ s: CFSocket!)
```

## Parameters

- `s`: The CFSocket object to invalidate.

## Discussion

Discussion You should always invalidate a socket object when you are through using it. Invalidating a CFSocket object prevents the object from sending or receiving any more messages, but does not release the socket object itself. If a run loop source was created for s, the run loop source is invalidated. If a release callback was specified in CFSocketContext object, this function calls it to release the object in the  info field (which was provided when s was created). By default, this call closes the underlying socket. If you have explicitly cleared the kCFSocketCloseOnInvalidate flag by calling CFSocketSetSocketFlags(_:_:), you must close the socket yourself after calling this function.

## See Also

### Using Sockets

- [CFSocketConnectToAddress(_:_:_:)](corefoundation/cfsocketconnecttoaddress(_:_:_:).md)
- [CFSocketCreateRunLoopSource(_:_:_:)](corefoundation/cfsocketcreaterunloopsource(_:_:_:).md)
- [CFSocketGetTypeID()](corefoundation/cfsocketgettypeid().md)
- [CFSocketIsValid(_:)](corefoundation/cfsocketisvalid(_:).md)
- [CFSocketSendData(_:_:_:_:)](corefoundation/cfsocketsenddata(_:_:_:_:).md)
