---
name: "xs_setctxopt"
section: "3"
platform: "linux"
package: "libxs-dev"
version: "1.2.0-2"
release: "Debian 10 (Buster)"
platforms: ["linux"]
url: "https://new.carta.tech/xs_setctxopt"
---

# xs\_setctxopt(3)

set Crossroads context options

## NAME

xs\_setctxopt - set Crossroads context options

## SYNOPSIS

**int xs\_setctxopt (void** *\*context***, int** *option\_name***, const void** *\*option\_value***, size\_t** *option\_len***);**

## DESCRIPTION

The *xs\_setctxopt()* function shall set the option specified by the *option\_name* argument to the value pointed to by the *option\_value* argument, for the Crossroads context pointed to by the *context* argument. The *option\_len* argument is the size of the option value in bytes.

**Caution**\

Context options take effect only if set with *xs\_setctxopt()* prior to creating the first socket in a given *context* with *xs\_socket()*.

The following options can be set with the *xs\_setctxopt()* function:

### XS\_MAX\_SOCKETS: Set maximum number of sockets

The *XS\_MAX\_SOCKETS* option shall set the maximum nuber of sockets that can be simultaneously active in the given *context*.

| | |
| --- | --- |
| Option value type | int |
| Option value unit | sockets |
| Default value | 512 |

### XS\_IO\_THREADS: Set number of worker threads

The *XS\_IO\_THREADS* option shall set the size of the thread pool created by the given *context* to handle I/O operations. The minimum value for this option is 1.

| | |
| --- | --- |
| Option value type | int |
| Option value unit | threads |
| Default value | 1 |

## RETURN VALUE

The *xs\_setctxopt()* function shall return zero if successful. Otherwise it shall return -1 and set *errno* to one of the values defined below.

## ERRORS

**EINVAL**

The requested option *option\_name* is unknown, or the requested *option\_len* or *option\_value* is invalid.

**EFAULT**

The provided *context* was invalid.

## EXAMPLE

**Setting the number of I/O threads for a context to four.**.

```
void *context = xs_init ();
int io_threads = 4;
rc = xs_setctxopt (context, XS_IO_THREADS, &io_threads, sizeof (io_threads));
assert (rc == 0);
/* The above call MUST be called before any socket is created in context */
void *socket = xs_socket (context, XS_PUB);
```

## SEE ALSO

[**xs\_init**(3)](/xs_init/3.md) [**xs**(7)](/xs/7.md)

## AUTHORS

The Crossroads documentation was written by Martin Sustrik \<**sustrik@250bpm.com**\[1\]\> and Martin Lucina \<**martin@lucina.net**\[2\]\>.

## NOTES

- 1\.

  sustrik@250bpm.com

  mailto:sustrik@250bpm.com

- 2\.

  martin@lucina.net

  mailto:martin@lucina.net
