Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions examples/test-tcp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
*/

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -140,7 +141,7 @@ static int createServer(int port) {
}

/* Listen on socket */
listen(fd, 1);
rc = listen(fd, 1);
if (rc < 0) {
perror("listen() failed");
close(fd);
Expand Down Expand Up @@ -179,9 +180,6 @@ int main(int argc, char** argv) {
int listenfd;
char smbuffer[10];

/* user_context will be pointer to socket */
scpi_context.user_context = NULL;

SCPI_Init(&scpi_context,
scpi_commands,
&scpi_interface,
Expand All @@ -190,13 +188,19 @@ int main(int argc, char** argv) {
scpi_input_buffer, SCPI_INPUT_BUFFER_LENGTH,
scpi_error_queue_data, SCPI_ERROR_QUEUE_SIZE);

signal(SIGPIPE, SIG_IGN);

listenfd = createServer(5025);

while (1) {
int clifd;
struct sockaddr_in cliaddr;
socklen_t clilen;

/* wait for a user to connect */
rc = waitServer(clifd);
if (rc < 0) continue;

clilen = sizeof (cliaddr);
clifd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen);

Expand Down