Data Structures | Macros | Typedefs | Functions | Variables
silink.h File Reference
#include "singularconfig.h"
#include "omalloc/omalloc.h"
#include "kernel/structs.h"
#include "Singular/links/sing_dbm.h"
#include "Singular/lists.h"
#include "Singular/attrib.h"

Go to the source code of this file.

Data Structures

Macros

#define SI_LINK_CLOSE   0
 
#define SI_LINK_OPEN   1
 
#define SI_LINK_READ   2
 
#define SI_LINK_WRITE   4
 
#define SI_LINK_CLOSE_P(l)   (!(l)->flags)
 
#define SI_LINK_OPEN_P(l)   ((l)->flags & SI_LINK_OPEN)
 
#define SI_LINK_W_OPEN_P(l)   ((l)->flags & SI_LINK_WRITE)
 
#define SI_LINK_R_OPEN_P(l)   ((l)->flags & SI_LINK_READ)
 
#define SI_LINK_RW_OPEN_P(l)   (SI_LINK_W_OPEN_P(l) && SI_LINK_R_OPEN_P(l))
 
#define SI_LINK_SET_CLOSE_P(l)   ((l)->flags = SI_LINK_CLOSE)
 
#define SI_LINK_SET_OPEN_P(l, flag)   ((l)->flags |= SI_LINK_OPEN |flag)
 
#define SI_LINK_SET_W_OPEN_P(l)   ((l)->flags |= (SI_LINK_OPEN | SI_LINK_WRITE))
 
#define SI_LINK_SET_R_OPEN_P(l)   ((l)->flags |= (SI_LINK_OPEN | SI_LINK_READ))
 
#define SI_LINK_SET_RW_OPEN_P(l)   ((l)->flags |= (SI_LINK_OPEN | SI_LINK_READ | SI_LINK_WRITE))
 

Typedefs

typedef ip_link * si_link
 
typedef BOOLEAN(* slOpenProc) (si_link l, short flag, leftv h)
 
typedef BOOLEAN(* slWriteProc) (si_link l, leftv lv)
 
typedef BOOLEAN(* slCloseProc) (si_link l)
 
typedef BOOLEAN(* slPrepCloseProc) (si_link l)
 
typedef BOOLEAN(* slKillProc) (si_link l)
 
typedef leftv(* slReadProc) (si_link l)
 
typedef leftv(* slRead2Proc) (si_link l, leftv a)
 
typedef BOOLEAN(* slDumpProc) (si_link l)
 
typedef BOOLEAN(* slGetDumpProc) (si_link l)
 
typedef const char *(* slStatusProc) (si_link l, const char *request)
 
typedef BOOLEAN(* slSetRingProc) (si_link l, ring r, BOOLEAN send)
 
typedef link_structlink_list
 

Functions

BOOLEAN slOpen (si_link l, short flag, leftv h)
 
BOOLEAN slClose (si_link l)
 
BOOLEAN slPrepClose (si_link l)
 
leftv slRead (si_link l, leftv a=NULL)
 
BOOLEAN slWrite (si_link l, leftv v)
 
BOOLEAN slDump (si_link l)
 
BOOLEAN slGetDump (si_link l)
 
const char * slStatus (si_link l, const char *request)
 
BOOLEAN slInit (si_link l, char *str)
 
void slKill (si_link l)
 
void slCleanUp (si_link l)
 
void slStandardInit ()
 
static si_link slCopy (si_link l)
 
static char * slString (si_link l)
 
int slStatusSsiL (lists L, int timeout)
 
int ssiBatch (const char *host, const char *port)
 

Variables

omBin s_si_link_extension_bin
 
omBin sip_link_bin
 
omBin ip_link_bin
 
link_list ssiToBeClosed
 
volatile BOOLEAN ssiToBeClosed_inactive
 

Data Structure Documentation

◆ s_si_link_extension

struct s_si_link_extension

Definition at line 36 of file silink.h.

Data Fields
slCloseProc Close
slDumpProc Dump
slGetDumpProc GetDump
slKillProc Kill
si_link_extension next
slOpenProc Open
slPrepCloseProc PrepClose
slReadProc Read
slRead2Proc Read2
slSetRingProc SetRing
slStatusProc Status
const char * type
slWriteProc Write

◆ sip_link

struct sip_link

Definition at line 53 of file silink.h.

Data Fields
void * data
BITSET flags
si_link_extension m
char * mode
char * name
short ref

◆ link_struct

struct link_struct

Definition at line 121 of file silink.h.

Data Fields
si_link l
void * next
leftv u

Macro Definition Documentation

◆ SI_LINK_CLOSE

#define SI_LINK_CLOSE   0

Definition at line 64 of file silink.h.

◆ SI_LINK_CLOSE_P

#define SI_LINK_CLOSE_P (   l)    (!(l)->flags)

Definition at line 70 of file silink.h.

◆ SI_LINK_OPEN

#define SI_LINK_OPEN   1

Definition at line 65 of file silink.h.

◆ SI_LINK_OPEN_P

#define SI_LINK_OPEN_P (   l)    ((l)->flags & SI_LINK_OPEN)

Definition at line 71 of file silink.h.

◆ SI_LINK_R_OPEN_P

#define SI_LINK_R_OPEN_P (   l)    ((l)->flags & SI_LINK_READ)

Definition at line 73 of file silink.h.

◆ SI_LINK_READ

#define SI_LINK_READ   2

Definition at line 66 of file silink.h.

◆ SI_LINK_RW_OPEN_P

#define SI_LINK_RW_OPEN_P (   l)    (SI_LINK_W_OPEN_P(l) && SI_LINK_R_OPEN_P(l))

Definition at line 74 of file silink.h.

◆ SI_LINK_SET_CLOSE_P

#define SI_LINK_SET_CLOSE_P (   l)    ((l)->flags = SI_LINK_CLOSE)

Definition at line 76 of file silink.h.

◆ SI_LINK_SET_OPEN_P

#define SI_LINK_SET_OPEN_P (   l,
  flag 
)    ((l)->flags |= SI_LINK_OPEN |flag)

Definition at line 77 of file silink.h.

◆ SI_LINK_SET_R_OPEN_P

#define SI_LINK_SET_R_OPEN_P (   l)    ((l)->flags |= (SI_LINK_OPEN | SI_LINK_READ))

Definition at line 79 of file silink.h.

◆ SI_LINK_SET_RW_OPEN_P

#define SI_LINK_SET_RW_OPEN_P (   l)    ((l)->flags |= (SI_LINK_OPEN | SI_LINK_READ | SI_LINK_WRITE))

Definition at line 80 of file silink.h.

◆ SI_LINK_SET_W_OPEN_P

#define SI_LINK_SET_W_OPEN_P (   l)    ((l)->flags |= (SI_LINK_OPEN | SI_LINK_WRITE))

Definition at line 78 of file silink.h.

◆ SI_LINK_W_OPEN_P

#define SI_LINK_W_OPEN_P (   l)    ((l)->flags & SI_LINK_WRITE)

Definition at line 72 of file silink.h.

◆ SI_LINK_WRITE

#define SI_LINK_WRITE   4

Definition at line 67 of file silink.h.

Typedef Documentation

◆ link_list

Definition at line 128 of file silink.h.

◆ si_link

typedef ip_link* si_link

Definition at line 20 of file silink.h.

◆ slCloseProc

typedef BOOLEAN(* slCloseProc) (si_link l)

Definition at line 26 of file silink.h.

◆ slDumpProc

typedef BOOLEAN(* slDumpProc) (si_link l)

Definition at line 31 of file silink.h.

◆ slGetDumpProc

typedef BOOLEAN(* slGetDumpProc) (si_link l)

Definition at line 32 of file silink.h.

◆ slKillProc

typedef BOOLEAN(* slKillProc) (si_link l)

Definition at line 28 of file silink.h.

◆ slOpenProc

typedef BOOLEAN(* slOpenProc) (si_link l, short flag, leftv h)

Definition at line 24 of file silink.h.

◆ slPrepCloseProc

typedef BOOLEAN(* slPrepCloseProc) (si_link l)

Definition at line 27 of file silink.h.

◆ slRead2Proc

typedef leftv(* slRead2Proc) (si_link l, leftv a)

Definition at line 30 of file silink.h.

◆ slReadProc

typedef leftv(* slReadProc) (si_link l)

Definition at line 29 of file silink.h.

◆ slSetRingProc

typedef BOOLEAN(* slSetRingProc) (si_link l, ring r, BOOLEAN send)

Definition at line 34 of file silink.h.

◆ slStatusProc

typedef const char*(* slStatusProc) (si_link l, const char *request)

Definition at line 33 of file silink.h.

◆ slWriteProc

typedef BOOLEAN(* slWriteProc) (si_link l, leftv lv)

Definition at line 25 of file silink.h.

Function Documentation

◆ slCleanUp()

void slCleanUp ( si_link  l)

Definition at line 126 of file silink.cc.

127 {
128  defer_shutdown++;
129  (l->ref)--;
130  if (l->ref == 0)
131  {
132  if (SI_LINK_OPEN_P(l))
133  {
134  if (l->m->Close != NULL) l->m->Close(l);
135  }
136  if ((l->data != NULL) && (l->m->Kill != NULL)) l->m->Kill(l);
137  omFree((ADDRESS)l->name);
138  omFree((ADDRESS)l->mode);
139  memset((void *) l, 0, sizeof(ip_link));
140  }
141  defer_shutdown--;
142  if (!defer_shutdown && do_shutdown) m2_end(1);
143 }
void * ADDRESS
Definition: auxiliary.h:133
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:77
#define omFree(addr)
Definition: omAllocDecl.h:261
void m2_end(int i)
Definition: misc_ip.cc:1096
#define NULL
Definition: omList.c:12
volatile int defer_shutdown
Definition: cntrlc.cc:78
int l
Definition: cfEzgcd.cc:93

◆ slClose()

BOOLEAN slClose ( si_link  l)

Definition at line 241 of file silink.cc.

242 {
243 
244  if(! SI_LINK_OPEN_P(l))
245  return FALSE;
246 
247  defer_shutdown++;
248  BOOLEAN res = TRUE;
249  if (l->m->Close != NULL)
250  {
251  res = l->m->Close(l);
252  if (res)
253  Werror("close: Error for link of type: %s, mode: %s, name: %s",
254  l->m->type, l->mode, l->name);
255  }
256  defer_shutdown--;
257  if (!defer_shutdown && do_shutdown) m2_end(1);
259  return res;
260 }
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
CanonicalForm res
Definition: facAbsFact.cc:64
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:77
void m2_end(int i)
Definition: misc_ip.cc:1096
#define NULL
Definition: omList.c:12
volatile int defer_shutdown
Definition: cntrlc.cc:78
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ slCopy()

static si_link slCopy ( si_link  l)
inlinestatic

Definition at line 94 of file silink.h.

95 {
96  l->ref++;
97  return l;
98 }
int l
Definition: cfEzgcd.cc:93

◆ slDump()

BOOLEAN slDump ( si_link  l)

Definition at line 345 of file silink.cc.

346 {
347  BOOLEAN res;
348 
349  if(! SI_LINK_W_OPEN_P(l)) // open w ?
350  {
351  if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
352  }
353 
354  if(SI_LINK_W_OPEN_P(l))
355  { // now open w
356  if (l->m->Dump != NULL)
357  res = l->m->Dump(l);
358  else
359  res = TRUE;
360 
361  if (res)
362  Werror("dump: Error for link of type %s, mode: %s, name: %s",
363  l->m->type, l->mode, l->name);
364  if (!SI_LINK_R_OPEN_P(l)) slClose(l); // do not close r/w links
365  return res;
366  }
367  else
368  {
369  Werror("dump: Error to open link of type %s, mode: %s, name: %s for writing",
370  l->m->type, l->mode, l->name);
371  return TRUE;
372  }
373 }
#define TRUE
Definition: auxiliary.h:98
CanonicalForm res
Definition: facAbsFact.cc:64
#define NULL
Definition: omList.c:12
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ slGetDump()

BOOLEAN slGetDump ( si_link  l)

Definition at line 375 of file silink.cc.

376 {
377  BOOLEAN res;
378 
379  if(! SI_LINK_R_OPEN_P(l)) // open r ?
380  {
381  if (slOpen(l, SI_LINK_READ,NULL)) return TRUE;
382  }
383 
384  if(SI_LINK_R_OPEN_P(l))
385  { // now open r
386  if (l->m->GetDump != NULL)
387  res = l->m->GetDump(l);
388  else
389  res = TRUE;
390 
391  if (res)
392  Werror("getdump: Error for link of type %s, mode: %s, name: %s",
393  l->m->type, l->mode, l->name);
394  //res|=slClose(l);
395  return res;
396  }
397  else
398  {
399  Werror("dump: Error open link of type %s, mode: %s, name: %s for reading",
400  l->m->type, l->mode, l->name);
401  return TRUE;
402  }
403 }
#define TRUE
Definition: auxiliary.h:98
CanonicalForm res
Definition: facAbsFact.cc:64
#define NULL
Definition: omList.c:12
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ slInit()

BOOLEAN slInit ( si_link  l,
char *  str 
)

Definition at line 47 of file silink.cc.

48 {
49  char *type = NULL, *mode = NULL, *name = NULL;
50  int i = 0, j;
51 
52  // set mode and type
53  if (istr != NULL)
54  {
55  // find the first colon char in istr
56  i = 0;
57  while (istr[i] != ':' && istr[i] != '\0') i++;
58  if (istr[i] == ':')
59  {
60  // if found, set type
61  if (i > 0)
62  {
63  istr[i] = '\0';
64  type = omStrDup(istr);
65  istr[i] = ':';
66  }
67  // and check for mode
68  j = ++i;
69  while (istr[j] != ' ' && istr[j] != '\0') j++;
70  if (j > i)
71  {
72  mode = omStrDup(&(istr[i]));
73  mode[j - i] = '\0';
74  }
75  // and for the name
76  while (istr[j] == ' '&& istr[j] != '\0') j++;
77  if (istr[j] != '\0') name = omStrDup(&(istr[j]));
78  }
79  else // no colon find -- string is entire name
80  {
81  j=0;
82  while (istr[j] == ' '&& istr[j] != '\0') j++;
83  if (istr[j] != '\0') name = omStrDup(&(istr[j]));
84  }
85  }
86 
87  // set the link extension
88  if (type != NULL)
89  {
90  si_link_extension s = si_link_root;
91  si_link_extension prev = s;
92 
93  while (strcmp(s->type, type) != 0)
94  {
95  if (s->next == NULL)
96  {
97  prev = s;
98  s = NULL;
99  break;
100  }
101  else
102  {
103  s = s->next;
104  }
105  }
106 
107  if (s != NULL)
108  l->m = s;
109  else
110  {
111  l->m = slTypeInit(prev, type);
112  }
113  omFree(type);
114  }
115  else
116  l->m = si_link_root;
117 
118  if (l->m == NULL) return TRUE;
119 
120  l->name = (name != NULL ? name : omStrDup(""));
121  l->mode = (mode != NULL ? mode : omStrDup(""));
122  l->ref = 1;
123  return FALSE;
124 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int j
Definition: facHensel.cc:105
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
#define omFree(addr)
Definition: omAllocDecl.h:261
int i
Definition: cfEzgcd.cc:125
char name(const Variable &v)
Definition: factory.h:180
#define NULL
Definition: omList.c:12
int l
Definition: cfEzgcd.cc:93
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ slKill()

void slKill ( si_link  l)

Definition at line 145 of file silink.cc.

146 {
147  defer_shutdown++;
148  slCleanUp(l);
149  if ((l!=NULL) &&(l->ref == 0))
151  defer_shutdown--;
152  if (!defer_shutdown && do_shutdown) m2_end(1);
153 }
void * ADDRESS
Definition: auxiliary.h:133
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:77
void m2_end(int i)
Definition: misc_ip.cc:1096
#define NULL
Definition: omList.c:12
volatile int defer_shutdown
Definition: cntrlc.cc:78
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
int l
Definition: cfEzgcd.cc:93

◆ slOpen()

BOOLEAN slOpen ( si_link  l,
short  flag,
leftv  h 
)

Definition at line 193 of file silink.cc.

194 {
195  BOOLEAN res = TRUE;
196  if (l!=NULL)
197  {
198 
199  if (l->m == NULL) slInit(l, ((char*)""));
200 
201  if (feOptValue(FE_OPT_NO_SHELL)) {WerrorS("no links allowed");return TRUE;}
202 
203  const char *c="_";;
204  if (h!=NULL) c=h->Name();
205 
206  if (SI_LINK_OPEN_P(l))
207  {
208  Warn("open: link of type: %s, mode: %s, name: %s is already open",
209  l->m->type, l->mode, l->name);
210  return FALSE;
211  }
212  else if (l->m->Open != NULL)
213  {
214  res = l->m->Open(l, flag, h);
215  if (res)
216  Werror("open: Error for link %s of type: %s, mode: %s, name: %s",
217  c, l->m->type, l->mode, l->name);
218  }
219  if (l->m->SetRing==NULL) l->m->SetRing=slSetRingDummy;
220  }
221  return res;
222 }
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char * Name()
Definition: subexpr.h:120
CanonicalForm res
Definition: facAbsFact.cc:64
#define NULL
Definition: omList.c:12
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93
#define Warn
Definition: emacs.cc:77

◆ slPrepClose()

BOOLEAN slPrepClose ( si_link  l)

Definition at line 224 of file silink.cc.

225 {
226 
227  if(! SI_LINK_OPEN_P(l))
228  return FALSE;
229 
230  BOOLEAN res = TRUE;
231  if (l->m->PrepClose != NULL)
232  {
233  res = l->m->PrepClose(l);
234  if (res)
235  Werror("close: Error for link of type: %s, mode: %s, name: %s",
236  l->m->type, l->mode, l->name);
237  }
238  return res;
239 }
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
CanonicalForm res
Definition: facAbsFact.cc:64
#define NULL
Definition: omList.c:12
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ slRead()

leftv slRead ( si_link  l,
leftv  a = NULL 
)

Definition at line 262 of file silink.cc.

263 {
264  leftv v = NULL;
265  if( ! SI_LINK_R_OPEN_P(l)) // open r ?
266  {
267 #ifdef HAVE_DBM
268 #ifdef USE_GDBM
269  if (! SI_LINK_CLOSE_P(l))
270  {
271  if (slClose(l)) return NULL;
272  }
273 #endif
274 #endif
275  if (slOpen(l, SI_LINK_READ,NULL)) return NULL;
276  }
277 
278  if (SI_LINK_R_OPEN_P(l))
279  { // open r
280  if (a==NULL)
281  {
282  if (l->m->Read != NULL) v = l->m->Read(l);
283  }
284  else
285  {
286  if (l->m->Read2 != NULL) v = l->m->Read2(l,a);
287  }
288  }
289  else
290  {
291  Werror("read: Error to open link of type %s, mode: %s, name: %s for reading",
292  l->m->type, l->mode, l->name);
293  return NULL;
294  }
295 
296  // here comes the eval:
297  if (v != NULL)
298  {
299  if (v->Eval() && !errorreported)
300  WerrorS("eval: failed");
301  }
302  else
303  Werror("read: Error for link of type %s, mode: %s, name: %s",
304  l->m->type, l->mode, l->name);
305  return v;
306 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
int Eval()
Definition: subexpr.cc:1837
void WerrorS(const char *s)
Definition: feFopen.cc:24
short errorreported
Definition: feFopen.cc:23
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define NULL
Definition: omList.c:12
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ slStandardInit()

void slStandardInit ( )

Definition at line 577 of file asciiLink.cc.

578 {
579  si_link_extension s;
582  si_link_root->Close=slCloseAscii;
583  si_link_root->Kill=NULL;
585  si_link_root->Read2=slReadAscii2;
586  si_link_root->Write=slWriteAscii;
588  si_link_root->GetDump=slGetDumpAscii;
589  si_link_root->Status=slStatusAscii;
590  si_link_root->type="ASCII";
591  s = si_link_root;
592  s->next = NULL;
593 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define NULL
Definition: omList.c:12

◆ slStatus()

const char* slStatus ( si_link  l,
const char *  request 
)

Definition at line 155 of file silink.cc.

156 {
157  if (l == NULL) return "empty link";
158  else if (l->m == NULL) return "unknown link type";
159  else if (strcmp(request, "type") == 0) return l->m->type;
160  else if (strcmp(request, "mode") == 0) return l->mode;
161  else if (strcmp(request, "name") == 0) return l->name;
162  else if (strcmp(request, "exists") ==0)
163  {
164  struct stat buf;
165  if (si_lstat(l->name,&buf)==0) return "yes";
166  else return "no";
167  }
168  else if (strcmp(request, "open") == 0)
169  {
170  if (SI_LINK_OPEN_P(l)) return "yes";
171  else return "no";
172  }
173  else if (strcmp(request, "openread") == 0)
174  {
175  if (SI_LINK_R_OPEN_P(l)) return "yes";
176  else return "no";
177  }
178  else if (strcmp(request, "openwrite") == 0)
179  {
180  if (SI_LINK_W_OPEN_P(l)) return "yes";
181  else return "no";
182  }
183  else if (l->m->Status == NULL) return "unknown status request";
184  else return l->m->Status(l, request);
185 }
int status int void * buf
Definition: si_signals.h:59
#define NULL
Definition: omList.c:12
int l
Definition: cfEzgcd.cc:93

◆ slStatusSsiL()

int slStatusSsiL ( lists  L,
int  timeout 
)

Definition at line 1655 of file ssiLink.cc.

1656 {
1657 // input: L: a list with links of type
1658 // ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
1659 // Note: Not every entry in L must be set.
1660 // timeout: timeout for select in micro-seconds
1661 // or -1 for infinity
1662 // or 0 for polling
1663 // returns: ERROR (via Werror): L has wrong elements or link not open
1664 // -2: select returns an error
1665 // -1: the read state of all links is eof
1666 // 0: timeout (or polling): none ready,
1667 // i>0: (at least) L[i] is ready
1668  si_link l;
1669  ssiInfo *d;
1670  int d_fd;
1671  fd_set mask, fdmask;
1672  FD_ZERO(&fdmask);
1673  FD_ZERO(&mask);
1674  int max_fd=0; /* 1 + max fd in fd_set */
1675 
1676  /* timeout */
1677  struct timeval wt;
1678  struct timeval *wt_ptr=&wt;
1679  int startingtime = getRTimer()/TIMER_RESOLUTION; // in seconds
1680  if (timeout== -1)
1681  {
1682  wt_ptr=NULL;
1683  }
1684  else
1685  {
1686  wt.tv_sec = timeout / 1000000;
1687  wt.tv_usec = timeout % 1000000;
1688  }
1689 
1690  /* auxiliary variables */
1691  int i;
1692  int j;
1693  int k;
1694  int s;
1695  char fdmaskempty;
1696 
1697  /* check the links and fill in fdmask */
1698  /* check ssi links for ungetc_buf */
1699  for(i=L->nr; i>=0; i--)
1700  {
1701  if (L->m[i].Typ()!=DEF_CMD)
1702  {
1703  if (L->m[i].Typ()!=LINK_CMD)
1704  { WerrorS("all elements must be of type link"); return -2;}
1705  l=(si_link)L->m[i].Data();
1706  if(SI_LINK_OPEN_P(l)==0)
1707  { WerrorS("all links must be open"); return -2;}
1708  if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
1709  || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
1710  && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
1711  {
1712  WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
1713  return -2;
1714  }
1715  if (strcmp(l->m->type,"ssi")==0)
1716  {
1717  d=(ssiInfo*)l->data;
1718  d_fd=d->fd_read;
1719  if (!s_isready(d->f_read))
1720  {
1721  FD_SET(d_fd, &fdmask);
1722  if (d_fd > max_fd) max_fd=d_fd;
1723  }
1724  else
1725  return i+1;
1726  }
1727  else
1728  {
1729  Werror("wrong link type >>%s<<",l->m->type);
1730  return -2;
1731  }
1732  }
1733  }
1734  max_fd++;
1735 
1736 do_select:
1737  /* copy fdmask to mask */
1738  FD_ZERO(&mask);
1739  for(k = 0; k < max_fd; k++)
1740  {
1741  if(FD_ISSET(k, &fdmask))
1742  {
1743  FD_SET(k, &mask);
1744  }
1745  }
1746 
1747  /* check with select: chars waiting: no -> not ready */
1748  s = si_select(max_fd, &mask, NULL, NULL, wt_ptr);
1749  if (s==-1)
1750  {
1751  WerrorS("error in select call");
1752  return -2; /*error*/
1753  }
1754  if (s==0)
1755  {
1756  return 0; /*poll: not ready */
1757  }
1758  else /* s>0, at least one ready (the number of fd which are ready is s)*/
1759  {
1760  j=0;
1761  while (j<=max_fd) { if (FD_ISSET(j,&mask)) break; j++; }
1762  for(i=L->nr; i>=0; i--)
1763  {
1764  if (L->m[i].rtyp==LINK_CMD)
1765  {
1766  l=(si_link)L->m[i].Data();
1767  if (strcmp(l->m->type,"ssi")==0)
1768  {
1769  d=(ssiInfo*)l->data;
1770  d_fd=d->fd_read;
1771  if(j==d_fd) break;
1772  }
1773  else
1774  {
1775  Werror("wrong link type >>%s<<",l->m->type);
1776  return -2;
1777  }
1778  }
1779  }
1780  // only ssi links:
1781  loop
1782  {
1783  /* yes: read 1 char*/
1784  /* if \n, check again with select else ungetc(c), ready*/
1785  /* setting: d: current ssiInfo, j current fd, i current entry in L*/
1786  int c=s_getc(d->f_read);
1787  //Print("try c=%d\n",c);
1788  if (c== -1) /* eof */
1789  {
1790  FD_CLR(j,&fdmask);
1791  fdmaskempty = 1;
1792  for(k = 0; k < max_fd; k++)
1793  {
1794  if(FD_ISSET(k, &fdmask))
1795  {
1796  fdmaskempty = 0;
1797  break;
1798  }
1799  }
1800  if(fdmaskempty)
1801  {
1802  return -1;
1803  }
1804  if(timeout != -1)
1805  {
1806  timeout = si_max(0,
1807  timeout - 1000000*(getRTimer()/TIMER_RESOLUTION - startingtime));
1808  wt.tv_sec = timeout / 1000000;
1809  wt.tv_usec = (timeout % 1000000);
1810  }
1811  goto do_select;
1812  }
1813 
1814  else if (isdigit(c))
1815  { s_ungetc(c,d->f_read); return i+1; }
1816  else if (c>' ')
1817  {
1818  Werror("unknown char in ssiLink(%d)",c);
1819  return -2;
1820  }
1821  /* else: next char */
1822  goto do_select;
1823  }
1824  }
1825 }
Definition: s_buff.h:20
const CanonicalForm int s
Definition: facAbsFact.cc:55
sleftv * m
Definition: lists.h:46
int j
Definition: facHensel.cc:105
int getRTimer()
Definition: timer.cc:170
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:92
#define loop
Definition: structs.h:80
int Typ()
Definition: subexpr.cc:1033
int s_getc(s_buff F)
Definition: s_buff.cc:58
s_buff f_read
Definition: s_buff.h:22
if(yy_init)
Definition: libparse.cc:1418
#define TIMER_RESOLUTION
Definition: mod2.h:34
Definition: tok.h:58
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:99
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
int i
Definition: cfEzgcd.cc:125
int nr
Definition: lists.h:44
Definition: tok.h:117
#define NULL
Definition: omList.c:12
int rtyp
Definition: subexpr.h:91
void * Data()
Definition: subexpr.cc:1176
int fd_read
Definition: s_buff.h:26
int s_isready(s_buff F)
Definition: s_buff.cc:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ slString()

static char* slString ( si_link  l)
inlinestatic

Definition at line 101 of file silink.h.

102 {
103  if (l->name != NULL)
104  {
105  return omStrDup(l->name);
106  }
107  else
108  {
109  return omStrDup("");
110  }
111 }
#define NULL
Definition: omList.c:12
int l
Definition: cfEzgcd.cc:93
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ slWrite()

BOOLEAN slWrite ( si_link  l,
leftv  v 
)

Definition at line 308 of file silink.cc.

309 {
310  BOOLEAN res;
311 
312  if(! SI_LINK_W_OPEN_P(l)) // open w ?
313  {
314 #ifdef HAVE_DBM
315 #ifdef USE_GDBM
316  if (! SI_LINK_CLOSE_P(l))
317  {
318  if (slClose(l)) return TRUE;
319  }
320 #endif
321 #endif
322  if (slOpen(l, SI_LINK_WRITE,NULL)) return TRUE;
323  }
324 
325  if (SI_LINK_W_OPEN_P(l))
326  { // now open w
327  if (l->m->Write != NULL)
328  res = l->m->Write(l,v);
329  else
330  res = TRUE;
331 
332  if (res)
333  Werror("write: Error for link of type %s, mode: %s, name: %s",
334  l->m->type, l->mode, l->name);
335  return res;
336  }
337  else
338  {
339  Werror("write: Error to open link of type %s, mode: %s, name: %s for writing",
340  l->m->type, l->mode, l->name);
341  return TRUE;
342  }
343 }
#define TRUE
Definition: auxiliary.h:98
CanonicalForm res
Definition: facAbsFact.cc:64
#define NULL
Definition: omList.c:12
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int l
Definition: cfEzgcd.cc:93

◆ ssiBatch()

int ssiBatch ( const char *  host,
const char *  port 
)

Definition at line 1827 of file ssiLink.cc.

1829 {
1831  char *buf=(char*)omAlloc(256);
1832  sprintf(buf,"ssi:connect %s:%s",host,port);
1833  slInit(l, buf);
1834  omFreeSize(buf,256);
1835  if (slOpen(l,SI_LINK_OPEN,NULL)) return 1;
1837 
1838  idhdl id = enterid("link_ll", 0, LINK_CMD, &IDROOT, FALSE);
1839  IDLINK(id) = l;
1840 
1841  loop
1842  {
1843  leftv h=ssiRead1(l); /*contains an exit.... */
1844  if (feErrors != NULL && *feErrors != '\0')
1845  {
1846  // handle errors:
1847  PrintS(feErrors); /* currently quite simple */
1848  *feErrors = '\0';
1849  }
1850  ssiWrite(l,h);
1851  h->CleanUp();
1852  omFreeBin(h, sleftv_bin);
1853  }
1854  /* never reached*/
1855  exit(0);
1856 }
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define IDLINK(a)
Definition: ipid.h:133
#define FALSE
Definition: auxiliary.h:94
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define IDROOT
Definition: ipid.h:18
#define loop
Definition: structs.h:80
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: idrec.h:34
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:265
char * feErrors
Definition: reporter.cc:47
int status int void * buf
Definition: si_signals.h:59
omBin sleftv_bin
Definition: subexpr.cc:41
void PrintS(const char *s)
Definition: reporter.cc:284
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
Definition: tok.h:117
#define NULL
Definition: omList.c:12
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
static Poly * h
Definition: janet.cc:971
int l
Definition: cfEzgcd.cc:93

Variable Documentation

◆ ip_link_bin

omBin ip_link_bin

Definition at line 41 of file silink.cc.

◆ s_si_link_extension_bin

omBin s_si_link_extension_bin

Definition at line 39 of file silink.cc.

◆ sip_link_bin

omBin sip_link_bin

Definition at line 40 of file silink.cc.

◆ ssiToBeClosed

link_list ssiToBeClosed

Definition at line 60 of file ssiLink.cc.

◆ ssiToBeClosed_inactive

volatile BOOLEAN ssiToBeClosed_inactive

Definition at line 61 of file ssiLink.cc.