vSockets allows you to set the minimum, maximum, and default size of communicating stream buffers. Names for the three options are:

SO_VMCI_BUFFER_SIZE – Default size of communicating buffers; 65536 bytes if not set.

SO_VMCI_BUFFER_MIN_SIZE – Minimum size of communicating buffers; defaults to 128 bytes.

SO_VMCI_BUFFER_MAX_SIZE – Maximum size of communicating buffers; defaults to 262144 bytes.

To set a new value for a socket option, call the setsockopt() function. To get a value, call getsockopt().

For example, to halve the size of the communications buffers from 65536 to 32768, and verify that the setting took effect, insert the following code:

uint64 setBuf = 32768, getBuf;
/* reduce buffer to above size and check */
if (setsockopt(sockfd, afVMCI, SO_VMCI_BUFFER_SIZE, (void *)&setBuf, sizeof setBuf) == -1) {
     perror(“setsockopt”);
     goto close;
}
if (getsockopt(sockfd, afVMCI, SO_VMCI_BUFFER_SIZE, (void *)&getBuf, sizeof getBuf) == -1) {
     perror(“getsockopt”);
     goto close;
}
if (getBuf != setBuf) {
					printf(stderr, “SO_VMCI_BUFFER_SIZE not set to size requested.\n”);
     goto close;
}

Parameters setBuf and getBuf must be declared 64 bit, even on 32-bit systems.

To have an effect, socket options must be set before establishing a connection. The buffer size is negotiated before the connection is established and stays consistent until the connection is closed. For a server socket, set options before any client establishes a connection. To be sure that this applies to all sockets, set options before calling listen(). For a client socket, set options before calling connect().