mirror of
https://github.com/aap/pdp6.git
synced 2026-01-27 12:42:39 +00:00
panel: implemented serial protocol used at LCM
This commit is contained in:
48
emu/util.c
48
emu/util.c
@@ -1,7 +1,12 @@
|
||||
#include "pdp6.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <netinet/tcp.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
|
||||
void
|
||||
strtolower(char *s)
|
||||
{
|
||||
@@ -85,3 +90,44 @@ win:
|
||||
freeaddrinfo(result);
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
void
|
||||
serve(int port, void (*handlecon)(int, void*), void *arg)
|
||||
{
|
||||
int sockfd, confd;
|
||||
socklen_t len;
|
||||
struct sockaddr_in server, client;
|
||||
int x;
|
||||
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(sockfd < 0){
|
||||
perror("error: socket");
|
||||
return;
|
||||
}
|
||||
|
||||
x = 1;
|
||||
setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, (void *)&x, sizeof x);
|
||||
|
||||
memset(&server, 0, sizeof(server));
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_addr.s_addr = INADDR_ANY;
|
||||
server.sin_port = htons(port);
|
||||
if(bind(sockfd, (struct sockaddr*)&server, sizeof(server)) < 0){
|
||||
perror("error: bind");
|
||||
return;
|
||||
}
|
||||
listen(sockfd, 5);
|
||||
len = sizeof(client);
|
||||
while(confd = accept(sockfd, (struct sockaddr*)&client, &len),
|
||||
confd >= 0)
|
||||
handlecon(confd, arg);
|
||||
perror("error: accept");
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
nodelay(int fd)
|
||||
{
|
||||
int flag = 1;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user