// SPDX-License-Identifier: GPL-2.0-only /* Control socket for client/server test execution * *Copyright(C)2017RedHat,Inc. * *Author:StefanHajnoczi<stefanha@redhat.com>
*/
/* The client and server may need to coordinate to avoid race conditions like *theclientattemptingtoconnecttoasocketthattheserverisnot *listeningonyet.Thecontrolsocketoffersacommunicationschannelfor *suchcoordinationtasks. * *Iftheclientcallscontrol_expectln("LISTENING"),thenitwillblockuntil *theservercallscontrol_writeln("LISTENING").Thisprovidesasimple *mechanismforcoordinatingbetweentheclientandtheserver.
*/
/* Open the control socket, either in server or client mode */ void control_init(constchar *control_host, constchar *control_port, bool server)
{ struct addrinfo hints = {
.ai_socktype = SOCK_STREAM,
}; struct addrinfo *result = NULL; struct addrinfo *ai; int ret;
ret = getaddrinfo(control_host, control_port, &hints, &result); if (ret != 0) {
fprintf(stderr, "%s\n", gai_strerror(ret)); exit(EXIT_FAILURE);
}
for (ai = result; ai; ai = ai->ai_next) { int fd;
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (fd < 0) continue;
if (!server) { if (connect(fd, ai->ai_addr, ai->ai_addrlen) < 0) goto next;
control_fd = fd;
printf("Control socket connected to %s:%s.\n",
control_host, control_port); break;
}
/* Return the next line from the control socket (without the trailing newline). * *Theprogramterminatesifatimeoutoccurs. * *Thecallermustfree()thereturnedstring.
*/ char *control_readln(void)
{ char *buf = NULL;
size_t idx = 0;
size_t buflen = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.