Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Networking updates #3693

Draft
wants to merge 16 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
91 changes: 71 additions & 20 deletions M2/Macaulay2/d/actors2.dd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use evaluate;
use struct;
use sets;

header "#include <netdb.h>"; -- for NI_MAXHOST and NI_MAXSERV

dbmfirst(e:Expr):Expr := (
when e
is f:Database do dbmfirst(f)
Expand Down Expand Up @@ -398,99 +400,148 @@ export setStdIO (f:file):void := ( stdIO = f; setGlobalVariable(stdioS, Ex
export setStdError(f:file):void := ( stdError = f; setGlobalVariable(stderrS, Expr(stdError)));

openfilesfun(e:Expr):Expr := (
n := 0;
ff := openfiles;
while true do (
when ff
is null do break
is f:FileCell do (n=n+1; ff=f.next;));
v := new Sequence len n do (
ff = openfiles;
while true do (
when ff
is null do break
is f:FileCell do (provide f.file; ff=f.next;));
);
list(v));
when e
is a:Sequence do (
-- typical value: openFiles, List
if length(a) == 0 then (
n := 0;
ff := openfiles;
while true do (
when ff
is null do break
is f:FileCell do (n=n+1; ff=f.next;));
v := new Sequence len n do (
ff = openfiles;
while true do (
when ff
is null do break
is f:FileCell do (provide f.file; ff=f.next;));
);
list(v))
else WrongNumArgs(0))
else WrongNumArgs(0));
setupfun("openFiles",openfilesfun);
openIn(filename:Expr):Expr := (
when filename
-- # typical value: openIn, File, File
is f:file do (
when openIn(f)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
-- # typical value: openIn, String, File
is f:stringCell do (
when openIn(f.v)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
is Error do filename
else WrongArgString());
else WrongArg("a file or string"));
setupfun("openIn",openIn);
openOut(filename:Expr):Expr := (
when filename
-- # typical value: openOut, File, File
is f:file do (
when openOut(f)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
-- # typical value: openOut, String, File
is f:stringCell do (
when openOut(f.v)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
is Error do filename
else WrongArgString());
setupfun("openOut",openOut);
openOutAppend(filename:Expr):Expr := (
when filename
-- # typical value: openOutAppend, File, File
is f:file do (
when openOut(f)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
-- # typical value: openOutAppend, String, File
is f:stringCell do (
when openOutAppend(f.v)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
is Error do filename
else WrongArgString());
setupfun("openOutAppend",openOutAppend);
openInOut(filename:Expr):Expr := (
when filename
-- # typical value: openInOut, File, File
is f:file do (
when openInOut(f)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
-- # typical value: openInOut, String, File
is f:stringCell do (
when openInOut(f.v)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
is Error do filename
else WrongArgString());
setupfun("openInOut",openInOut);
openListener(filename:Expr):Expr := (
when filename
-- # typical value: openListener, String, File
is f:stringCell do (
when openListener(f.v)
is g:file do Expr(g)
is m:errmsg do buildErrorPacket(m.message))
is Error do filename
else WrongArgString());
setupfun("openListener",openListener);
isOpen(e:Expr):Expr := (
when e
-- # typical value: isOpen, File, Boolean
is f:file do toExpr(f.listener || f.input || f.output)
-- # typical value: isOpen, Database, Boolean
is x:Database do toExpr(x.isopen)
else WrongArg("a file or database"));
setupfun("isOpen",isOpen);
isInputFile(e:Expr):Expr := (
when e
-- # typical value: isInputFile, File, Boolean
is f:file do toExpr(f.input)
else False);
setupfun("isInputFile",isInputFile);
isOutputFile(e:Expr):Expr := (
when e
-- # typical value: isOutputFile, File, Boolean
is f:file do toExpr(f.output)
else False);
setupfun("isOutputFile",isOutputFile);
isListener(e:Expr):Expr := (
when e
-- # typical value: isListener, File, Boolean
is f:file do toExpr(f.listener)
else False);
setupfun("isListener",isListener);
getPeerName(e:Expr):Expr := (
when e
-- # typical value: getPeerName, File, Sequence
is f:file do (
if f.input then (
host := new string len Ccode(int, "NI_MAXHOST") do provide ' ';
serv := new string len Ccode(int, "NI_MAXSERV") do provide ' ';
r := getpeername(f.infd, host, serv);
if r < 0 then buildErrorPacket(
"can't get peer name: " + netstrerror(r))
else seq(toExpr(host), toExpr(serv)))
else WrongArg("an input file"))
else WrongArg("a file"));
setupfun("getPeerName", getPeerName);
getSocketName(e:Expr):Expr := (
when e
-- # typical value: getSocketName, File, Sequence
is f:file do (
fd := 0;
if f.listener then fd = f.listenerfd
else if f.output then fd = f.outfd
else return WrongArg("a listener or output file");
host := new string len Ccode(int, "NI_MAXHOST") do provide ' ';
serv := new string len Ccode(int, "NI_MAXSERV") do provide ' ';
r := getsockname(fd, host, serv);
if r < 0 then buildErrorPacket(
"can't get socket name: " + netstrerror(r))
else seq(toExpr(host), toExpr(serv)))
else WrongArg("a file"));
setupfun("getSocketName", getSocketName);

header "
#if WITH_MYSQL
Expand Down
1 change: 0 additions & 1 deletion M2/Macaulay2/d/expr.d
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ export pseudocodeClosureClass := newtypeof(pseudocodeClass);

--Error Handling
export buildErrorPacket(message:string):Expr := Expr(Error(dummyPosition,message,nullE,false,dummyFrame));
export buildErrorPacketErrno(msg:string,errnum:int):Expr := buildErrorPacket( msg + ": " + strerror(errnum) );

export quoteit(name:string):string := "'" + name + "'";
export NotYet(desc:string):Expr := buildErrorPacket(desc + " not implemented yet");
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/hashtables.dd
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ installIt(numtypes:int,assgnmt:bool,h:HashTable,key:Expr,value:Expr):Expr := (
else buildErrorPacket(messx));
-----------------------------------------------------------------------------
-- nullary methods
export NullaryMethods := newHashTableWithHash(mutableHashTableClass,nothingClass);
export NullaryMethods := newHashTableWithHash(typeClass,nothingClass);
setupconst("nullaryMethods",Expr(NullaryMethods));
export lookup(e:Expr):Expr := (
r := lookup1(NullaryMethods,Expr(Sequence(e)));
Expand Down
Loading
Loading