mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-21 18:05:33 +00:00
This also involves removing unnecessary forward declarations, inserting
includes for all cross-file function references, making some definitions
static if they are not otherwise used, correcting errors that were exposed
by having correct prototypes.
new file: inc/allocmdsdefs.h
new file: inc/arith2defs.h
new file: inc/arith3defs.h
new file: inc/arith4defs.h
new file: inc/array2defs.h
new file: inc/array3defs.h
new file: inc/array4defs.h
new file: inc/array5defs.h
new file: inc/array6defs.h
new file: inc/arraydefs.h
new file: inc/bbtsubdefs.h
new file: inc/bindefs.h
new file: inc/bindsdefs.h
new file: inc/bitbltdefs.h
new file: inc/bltdefs.h
new file: inc/byteswapdefs.h
new file: inc/car-cdrdefs.h
new file: inc/chardevdefs.h
new file: inc/commondefs.h
new file: inc/conspagedefs.h
new file: inc/dbgtooldefs.h
new file: inc/dirdefs.h
new file: inc/drawdefs.h
new file: inc/dskdefs.h
new file: inc/dspifdefs.h
new file: inc/dspsubrsdefs.h
new file: inc/eqfdefs.h
new file: inc/etherdefs.h
new file: inc/findkeydefs.h
new file: inc/fpdefs.h
new file: inc/fvardefs.h
new file: inc/gc2defs.h
new file: inc/gcarraydefs.h
new file: inc/gccodedefs.h
new file: inc/gcdefs.h
new file: inc/gcfinaldefs.h
new file: inc/gchtfinddefs.h
new file: inc/gcmain3defs.h
new file: inc/gcoflowdefs.h
new file: inc/gcrcelldefs.h
new file: inc/gcrdefs.h
new file: inc/gcscandefs.h
new file: inc/gvar2defs.h
new file: inc/hacksdefs.h
new file: inc/hardrtndefs.h
new file: inc/inetdefs.h
new file: inc/initdspdefs.h
new file: inc/initkbddefs.h
new file: inc/initsoutdefs.h
modified: inc/inlineC.h
new file: inc/intcalldefs.h
new file: inc/kbdsubrsdefs.h
new file: inc/keyeventdefs.h
new file: inc/keylibdefs.h
new file: inc/kprintdefs.h
new file: inc/ldsoutdefs.h
new file: inc/lineblt8defs.h
new file: inc/lisp2cdefs.h
modified: inc/lispemul.h
new file: inc/llcolordefs.h
new file: inc/llstkdefs.h
modified: inc/lnk-inlineC.h
new file: inc/loopsopsdefs.h
new file: inc/lowlev1defs.h
new file: inc/lowlev2defs.h
new file: inc/lsthandldefs.h
new file: inc/maindefs.h
new file: inc/misc7defs.h
new file: inc/miscndefs.h
new file: inc/mkatomdefs.h
new file: inc/mkcelldefs.h
new file: inc/mvsdefs.h
new file: inc/osmsgdefs.h
new file: inc/perrnodefs.h
new file: inc/returndefs.h
new file: inc/rpcdefs.h
new file: inc/rplconsdefs.h
new file: inc/shiftdefs.h
new file: inc/storagedefs.h
new file: inc/subr0374defs.h
new file: inc/subrdefs.h
new file: inc/sxhashdefs.h
new file: inc/testtooldefs.h
new file: inc/timerdefs.h
new file: inc/typeofdefs.h
new file: inc/ubf1defs.h
new file: inc/ubf2defs.h
new file: inc/ubf3defs.h
new file: inc/ufsdefs.h
new file: inc/unixcommdefs.h
new file: inc/unwinddefs.h
new file: inc/uraiddefs.h
new file: inc/usrsubrdefs.h
new file: inc/uutilsdefs.h
new file: inc/vars3defs.h
new file: inc/vmemsavedefs.h
new file: inc/xbbtdefs.h
new file: inc/xcdefs.h
new file: inc/xcursordefs.h
new file: inc/xinitdefs.h
new file: inc/xlspwindefs.h
new file: inc/xmkicondefs.h
new file: inc/xrdoptdefs.h
new file: inc/xscrolldefs.h
new file: inc/xwinmandefs.h
new file: inc/z2defs.h
modified: src/allocmds.c
modified: src/arith2.c
modified: src/arith3.c
modified: src/arith4.c
modified: src/array.c
modified: src/array2.c
modified: src/array3.c
modified: src/array4.c
modified: src/array5.c
modified: src/array6.c
modified: src/bbtsub.c
modified: src/bin.c
modified: src/binds.c
modified: src/bitblt.c
modified: src/blt.c
modified: src/byteswap.c
modified: src/car-cdr.c
modified: src/chardev.c
modified: src/common.c
modified: src/conspage.c
modified: src/dbgtool.c
modified: src/dir.c
modified: src/draw.c
modified: src/dsk.c
modified: src/dspif.c
modified: src/dspsubrs.c
modified: src/eqf.c
modified: src/ether.c
modified: src/findkey.c
modified: src/foreign.c
modified: src/fp.c
modified: src/fvar.c
modified: src/gc.c
modified: src/gc2.c
modified: src/gcarray.c
modified: src/gccode.c
modified: src/gcfinal.c
modified: src/gchtfind.c
modified: src/gcmain3.c
modified: src/gcoflow.c
modified: src/gcr.c
modified: src/gcrcell.c
modified: src/gcscan.c
modified: src/gvar2.c
modified: src/hacks.c
modified: src/hardrtn.c
modified: src/inet.c
modified: src/initdsp.c
modified: src/initkbd.c
modified: src/initsout.c
modified: src/intcall.c
modified: src/kbdsubrs.c
modified: src/keyevent.c
modified: src/keylib.c
modified: src/kprint.c
modified: src/ldsout.c
modified: src/lineblt8.c
modified: src/lisp2c.c
modified: src/llcolor.c
modified: src/llstk.c
modified: src/loopsops.c
modified: src/lowlev1.c
modified: src/lowlev2.c
modified: src/lsthandl.c
modified: src/main.c
modified: src/misc7.c
modified: src/miscn.c
modified: src/mkatom.c
modified: src/mkcell.c
modified: src/mvs.c
modified: src/osmsg.c
modified: src/perrno.c
modified: src/return.c
modified: src/rpc.c
modified: src/rplcons.c
modified: src/setsout.c
modified: src/shift.c
modified: src/storage.c
modified: src/subr.c
modified: src/subr0374.c
modified: src/sxhash.c
modified: src/testtool.c
modified: src/timer.c
modified: src/truecolor.c
modified: src/tstsout.c
modified: src/typeof.c
modified: src/ubf1.c
modified: src/ubf2.c
modified: src/ubf3.c
modified: src/ufn.c
modified: src/ufs.c
modified: src/unixcomm.c
modified: src/unwind.c
modified: src/uraid.c
modified: src/usrsubr.c
modified: src/uutils.c
modified: src/vars3.c
modified: src/vmemsave.c
modified: src/xbbt.c
modified: src/xc.c
modified: src/xcursor.c
modified: src/xinit.c
modified: src/xlspwin.c
modified: src/xmkicon.c
modified: src/xrdopt.c
modified: src/xscroll.c
modified: src/xwinman.c
modified: src/z2.c
214 lines
5.9 KiB
C
214 lines
5.9 KiB
C
/* $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. */
|
|
/* Manufactured in the United States of America. */
|
|
/* */
|
|
/************************************************************************/
|
|
|
|
#include "version.h"
|
|
|
|
/************************************************************************/
|
|
/************************************************************************/
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/************************************************************************/
|
|
|
|
#ifndef DOS
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/time.h>
|
|
#include <netinet/in.h>
|
|
#include <netdb.h>
|
|
#include <errno.h>
|
|
#include <sys/ioctl.h>
|
|
#include <string.h> /* for memset/memcpy */
|
|
#endif /* DOS */
|
|
#include "lispemul.h"
|
|
#include "lispmap.h"
|
|
#include "lsptypes.h"
|
|
#include "lspglob.h"
|
|
#include "emlglob.h"
|
|
#include "adr68k.h"
|
|
#include "arith.h"
|
|
#include "locfile.h"
|
|
|
|
#include "rpcdefs.h"
|
|
#include "commondefs.h"
|
|
|
|
#define MAX_HOSTNAME_LENGTH 100
|
|
#define UDP_DATA_BLOCK_SIZE 1000
|
|
|
|
#ifdef OS5
|
|
#define ToMem memmove
|
|
#else
|
|
#define ToMem memcpy
|
|
#endif /* OS5 */
|
|
|
|
LispPTR rpc(LispPTR *args)
|
|
{
|
|
#ifndef DOS
|
|
/* Arguments are:
|
|
args[0]:Destination Address; hostname or internet address are both supported.
|
|
args[1]:Remote port for this program.
|
|
args[2]:Argument block pointer.
|
|
args[3]:Result Block pointer.
|
|
args[4]:Milliseconds before timeout
|
|
args[5]:Milliseconds between tries
|
|
args[6]:Argument block length
|
|
*/
|
|
char hostname[MAX_HOSTNAME_LENGTH];
|
|
struct hostent *hp;
|
|
struct servent *sp;
|
|
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 port;
|
|
int dontblock, dest, read_descriptors;
|
|
unsigned fromlen;
|
|
|
|
struct timeval pertry_timeout, total_timeout, time_waited;
|
|
|
|
/* Set timeout */
|
|
/* CONVERT FROM LISP TO C TYPES */
|
|
dest = GetTypeNumber(args[0]);
|
|
|
|
if ((dest == TYPE_FIXP) || (dest == TYPE_SMALLP)) {
|
|
N_GETNUMBER(args[0], dest, handle_error);
|
|
destaddr = (char *)&dest;
|
|
hp = gethostbyaddr(destaddr, sizeof(struct in_addr), AF_INET);
|
|
} else {
|
|
/* Convert Hostname */
|
|
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 */
|
|
msec_until_timeout = msec_until_timeout * 1000;
|
|
msec_between_tries = msec_between_tries * 1000;
|
|
|
|
/* Set up the timeouts */
|
|
total_timeout.tv_sec = msec_until_timeout / 1000000;
|
|
total_timeout.tv_usec = msec_until_timeout % 1000000;
|
|
pertry_timeout.tv_sec = msec_between_tries / 1000000;
|
|
pertry_timeout.tv_usec = msec_between_tries % 1000000;
|
|
|
|
/* 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;
|
|
|
|
dontblock = 1;
|
|
|
|
/* The sockets that rpc controls don't block */
|
|
#ifdef SYSVONLY
|
|
/* NEED TO FILL THIS IN PROPERLY */
|
|
#else
|
|
(void)ioctl(s, FIONBIO, &dontblock);
|
|
#endif /* SYSVONLY */
|
|
|
|
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;
|
|
|
|
/* 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)
|
|
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:
|
|
|
|
read_descriptors = mask;
|
|
|
|
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;
|
|
|
|
/* An error was generated, Unless it was a system error stop */
|
|
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:
|
|
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;
|
|
}
|
|
|
|
/* 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);
|
|
#endif /* DOS */
|
|
}
|