mirror of
https://github.com/Interlisp/maiko.git
synced 2026-02-13 03:14:32 +00:00
Reformat all C source files with Clang-format in Google style w/ 100 col width.
This commit is contained in:
145
src/rpc.c
Executable file → Normal file
145
src/rpc.c
Executable file → Normal file
@@ -1,10 +1,6 @@
|
||||
/* $Id: rpc.c,v 1.3 2001/12/24 01:09:06 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */
|
||||
static char *id = "$Id: rpc.c,v 1.3 2001/12/24 01:09:06 sybalsky Exp $ Copyright (C) Venue";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* (C) Copyright 1989-99 Venue. All Rights Reserved. */
|
||||
@@ -19,7 +15,6 @@ static char *id = "$Id: rpc.c,v 1.3 2001/12/24 01:09:06 sybalsky Exp $ Copyright
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/************************************************************************/
|
||||
/* */
|
||||
@@ -29,7 +24,6 @@ static char *id = "$Id: rpc.c,v 1.3 2001/12/24 01:09:06 sybalsky Exp $ Copyright
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
|
||||
#ifndef DOS
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
@@ -39,8 +33,8 @@ static char *id = "$Id: rpc.c,v 1.3 2001/12/24 01:09:06 sybalsky Exp $ Copyright
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <string.h> /* for memset/memcpy */
|
||||
#endif /* DOS */
|
||||
#include <string.h> /* for memset/memcpy */
|
||||
#endif /* DOS */
|
||||
#include "lispemul.h"
|
||||
#include "lispmap.h"
|
||||
#include "lsptypes.h"
|
||||
@@ -59,8 +53,7 @@ static char *id = "$Id: rpc.c,v 1.3 2001/12/24 01:09:06 sybalsky Exp $ Copyright
|
||||
#define ToMem memcpy
|
||||
#endif /* OS5 */
|
||||
|
||||
LispPTR rpc(args)
|
||||
LispPTR *args;
|
||||
LispPTR rpc(args) LispPTR *args;
|
||||
{
|
||||
#ifndef DOS
|
||||
/* Arguments are:
|
||||
@@ -78,7 +71,7 @@ LispPTR rpc(args)
|
||||
struct sockaddr_in sin, sin1, from;
|
||||
char *outbuf, *inbuf, *destaddr;
|
||||
register int s, msec_until_timeout, msec_between_tries, out_length;
|
||||
register int received, mask;
|
||||
register int received, mask;
|
||||
register int port;
|
||||
int dontblock, dest, fromlen, read_descriptors;
|
||||
|
||||
@@ -92,23 +85,22 @@ LispPTR rpc(args)
|
||||
N_GETNUMBER(args[0], dest, handle_error);
|
||||
destaddr = (char *)&dest;
|
||||
hp = gethostbyaddr(destaddr, sizeof(struct in_addr), AF_INET);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Convert Hostname */
|
||||
LispStringToCString(args[0],hostname, MAX_HOSTNAME_LENGTH);
|
||||
LispStringToCString(args[0], hostname, MAX_HOSTNAME_LENGTH);
|
||||
hp = gethostbyname(hostname);
|
||||
}
|
||||
|
||||
|
||||
N_GETNUMBER(args[1], port, handle_error);
|
||||
|
||||
/* Translate the buffer pointer into C pointers */
|
||||
outbuf = (char *)(Addr68k_from_LADDR(args[2]));
|
||||
inbuf = (char *)(Addr68k_from_LADDR(args[3]));
|
||||
|
||||
|
||||
N_GETNUMBER(args[4], msec_until_timeout, handle_error);
|
||||
|
||||
N_GETNUMBER(args[5], msec_between_tries, handle_error);
|
||||
|
||||
|
||||
N_GETNUMBER(args[6], out_length, handle_error);
|
||||
|
||||
/* Convert to micro seconds */
|
||||
@@ -124,107 +116,98 @@ LispPTR rpc(args)
|
||||
/* SET UP THE SOCKET */
|
||||
|
||||
/* Open the socket; Might want to make this non-blocking */
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
|
||||
goto handle_error;
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) goto handle_error;
|
||||
|
||||
dontblock = 1;
|
||||
|
||||
/* The sockets that rpc controls don't block */
|
||||
/* The sockets that rpc controls don't block */
|
||||
#ifdef SYSVONLY
|
||||
/* NEED TO FILL THIS IN PROPERLY */
|
||||
#else
|
||||
(void)ioctl(s, FIONBIO, &dontblock);
|
||||
(void)ioctl(s, FIONBIO, &dontblock);
|
||||
#endif /* SYSVONLY */
|
||||
|
||||
|
||||
memset((char *)&sin, 0, sizeof(sin));
|
||||
memset((char *)&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
bind(s, (struct sockaddr *)&sin, sizeof(sin));
|
||||
|
||||
/* Resolve the host address. */
|
||||
if (hp) {
|
||||
sin1.sin_family = hp->h_addrtype;
|
||||
ToMem((caddr_t) &sin1.sin_addr, hp->h_addr, hp->h_length);
|
||||
}
|
||||
else goto handle_error;
|
||||
ToMem((caddr_t)&sin1.sin_addr, hp->h_addr, hp->h_length);
|
||||
} else
|
||||
goto handle_error;
|
||||
|
||||
/* Convert to network byte order */
|
||||
sin1.sin_port = htons((u_short)port);
|
||||
|
||||
/* Send buffer out on the socket */
|
||||
if (sendto(s, outbuf, out_length, 0, (struct sockaddr *)&sin1,
|
||||
sizeof(sin1)) != out_length)
|
||||
if (sendto(s, outbuf, out_length, 0, (struct sockaddr *)&sin1, sizeof(sin1)) != out_length)
|
||||
goto handle_error;
|
||||
|
||||
/* Set the select mask */
|
||||
mask = 1 << s;
|
||||
|
||||
|
||||
/* Set up the timers */
|
||||
time_waited.tv_sec = 0;
|
||||
time_waited.tv_usec = 0;
|
||||
|
||||
/* Start the waiting loop */
|
||||
receive:
|
||||
|
||||
/* Start the waiting loop */
|
||||
receive:
|
||||
|
||||
read_descriptors = mask;
|
||||
|
||||
switch(select(32, (fd_set *)&read_descriptors, (fd_set *)NULL, (fd_set *)NULL,
|
||||
&pertry_timeout)){
|
||||
|
||||
switch (
|
||||
select(32, (fd_set *)&read_descriptors, (fd_set *)NULL, (fd_set *)NULL, &pertry_timeout)) {
|
||||
/* Per try timeout expired, Check the total timeout */
|
||||
case 0:
|
||||
time_waited.tv_sec += pertry_timeout.tv_sec;
|
||||
time_waited.tv_usec += pertry_timeout.tv_usec;
|
||||
while(time_waited.tv_usec >= 1000000) {
|
||||
time_waited.tv_sec++;
|
||||
time_waited.tv_usec -= 1000000;
|
||||
}
|
||||
/* If the time waited is greater than the total
|
||||
* timeout then there's an error
|
||||
*/
|
||||
if ((time_waited.tv_sec > total_timeout.tv_sec) ||
|
||||
((time_waited.tv_sec == total_timeout.tv_sec) &&
|
||||
(time_waited.tv_usec >= total_timeout.tv_usec)))
|
||||
goto handle_error;
|
||||
else break;
|
||||
|
||||
case 0:
|
||||
time_waited.tv_sec += pertry_timeout.tv_sec;
|
||||
time_waited.tv_usec += pertry_timeout.tv_usec;
|
||||
while (time_waited.tv_usec >= 1000000) {
|
||||
time_waited.tv_sec++;
|
||||
time_waited.tv_usec -= 1000000;
|
||||
}
|
||||
/* If the time waited is greater than the total
|
||||
* timeout then there's an error
|
||||
*/
|
||||
if ((time_waited.tv_sec > total_timeout.tv_sec) ||
|
||||
((time_waited.tv_sec == total_timeout.tv_sec) &&
|
||||
(time_waited.tv_usec >= total_timeout.tv_usec)))
|
||||
goto handle_error;
|
||||
else
|
||||
break;
|
||||
|
||||
/* An error was generated, Unless it was a system error stop */
|
||||
case -1:
|
||||
if (errno == EINTR)
|
||||
goto receive;
|
||||
else goto handle_error;
|
||||
case -1:
|
||||
if (errno == EINTR)
|
||||
goto receive;
|
||||
else
|
||||
goto handle_error;
|
||||
}
|
||||
/* Did something arrive for this socket */
|
||||
if ((read_descriptors & mask) == 0)
|
||||
goto receive;
|
||||
|
||||
/* Something arrived; try to get it */
|
||||
|
||||
getbuf:
|
||||
if ((read_descriptors & mask) == 0) goto receive;
|
||||
|
||||
/* Something arrived; try to get it */
|
||||
|
||||
getbuf:
|
||||
fromlen = sizeof(struct sockaddr);
|
||||
received = recvfrom(s, inbuf, UDP_DATA_BLOCK_SIZE, 0,
|
||||
(struct sockaddr *)&from, &fromlen);
|
||||
if (received < 0)
|
||||
switch(errno) {
|
||||
case EINTR:
|
||||
goto getbuf;
|
||||
case EWOULDBLOCK:
|
||||
goto receive;
|
||||
default:
|
||||
goto handle_error;
|
||||
received = recvfrom(s, inbuf, UDP_DATA_BLOCK_SIZE, 0, (struct sockaddr *)&from, &fromlen);
|
||||
if (received < 0) switch (errno) {
|
||||
case EINTR: goto getbuf;
|
||||
case EWOULDBLOCK: goto receive;
|
||||
default: goto handle_error;
|
||||
}
|
||||
|
||||
|
||||
/* close the socket */
|
||||
close(s);
|
||||
|
||||
|
||||
/* Return TRUE */
|
||||
return(ATOM_T);
|
||||
|
||||
/* Return NIL; Eventually we will need to return something more informative, perhaps errno
|
||||
* would be sufficient.
|
||||
*/
|
||||
handle_error:
|
||||
return(NIL_PTR);
|
||||
return (ATOM_T);
|
||||
|
||||
/* Return NIL; Eventually we will need to return something more informative, perhaps errno
|
||||
* would be sufficient.
|
||||
*/
|
||||
handle_error:
|
||||
return (NIL_PTR);
|
||||
#endif /* DOS */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user