<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFSocketInvalidate(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFSocketInvalidate"
  },
  "title" : "CFSocketInvalidate(_:)"
}
-->

# CFSocketInvalidate(_:)

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

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

## Parameters

`s`

The CFSocket object to invalidate.

## 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`](/documentation/CoreFoundation/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(_:_:)`](/documentation/CoreFoundation/CFSocketSetSocketFlags(_:_:)), you must close the socket yourself *after* calling this function.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)