// General setup for verbs with IRS that do not go through jtirs[12] // A verb u["n] using this function checks to see whether it has multiple cells; if so, // it calls here, giving a callback; we split the arguents into cells and call the callback, // which is often the same original function that called here. A jtrank2ex(J jt,A a,A w,A fs,I lr,I rr,AF f2){PROLOG(0042);A y,y0,ya,yw,z;B ab,b,wb; C*u,*uu,*v,*vv;I acn,acr,af,ak,ar,*as,at,k,mn,n=1,p,q,*s,wcn,wcr,wf,wk,wr,*ws,wt,yn,yr,*ys,yt; RZ(a&&w); at=AT(a); wt=AT(w); if(at&SPARSE||wt&SPARSE)R sprank2(a,w,fs,lr,rr,f2); // ?r=rank, ?s->shape, ?cr=effective rank, ?f=#frame, ?b=relative flag, for each argument ar=AR(a); as=AS(a); acr=efr(ar,lr); af=ar-acr; ab=ARELATIVE(a); wr=AR(w); ws=AS(w); wcr=efr(wr,rr); wf=wr-wcr; wb=ARELATIVE(w); if(!af&&!wf)R CALL2(f2,a,w,fs); // if there's only one cell, run on it, that's the result // multiple cells. Loop through them. // ?cn=number of atoms in a cell, ?k=#bytes in a cell, uv point to one cell before aw data // Allocate y? to hold one cell of ?, with uu,vv pointing to the data of y? RE(acn=prod(acr,as+af)); ak=acn*bp(at); u=CAV(a)-ak; NEWYA; RE(wcn=prod(wcr,ws+wf)); wk=wcn*bp(wt); v=CAV(w)-wk; NEWYW; // b means 'w frame is larger'; p=#larger frame; q=#shorter frame; s->larger frame // mn=#cells in larger frame (& therefore #cells in result); n=# times to repeat each cell // from shorter-frame argument b=af<=wf; p=b?wf:af; q=b?af:wf; s=b?ws:as; RE(mn=prod(p,s)); RE(n=prod(p-q,s+q)); ASSERT(!ICMP(as,ws,q),EVLENGTH); // error if frames are not same as prefix // Initialize y? to hold data for the first cell; but if ? is empty, set y? to a cell of fills if(AN(a))MOVEYA else RZ(ya=reshape(vec(INT,acr,as+af),filler(a))); if(AN(w))MOVEYW else RZ(yw=reshape(vec(INT,wcr,ws+wf),filler(w))); #define VALENCE 2 #define TEMPLATE 0 #include "cr_t.h" }
// ------------------------------------------------ // Function: icmp_parse() // ------------------------------------------------ // Input: Message buffer // Output: - // ------------------------------------------------ // Description: Parse a ICMP message // ------------------------------------------------ void icmp_parse(PPBUF pbuf) { // --------------------- // checksum verification // --------------------- icmp_checksum(pbuf->data, pbuf->size); if(chk_H != 0xff) return; if(chk_L != 0xff) return; // ------------------------------- // checks recognized message types // ------------------------------- switch(ICMP(pbuf->data)->type) { case PING_REQUEST: // --------- // answer it // --------- retain_buffer(pbuf); ip_answer(pbuf); ICMP(pbuf->data)->type = PING_REPLY; // --------------- // update checksum // --------------- ICMP(pbuf->data)->checksum = 0; icmp_checksum(pbuf->data, pbuf->size); ICMP(pbuf->data)->checksum = HTONS(~WORDOF(chk_H, chk_L)); // ---------------------------- // sends answer to IP interface // ---------------------------- ip_send(pbuf); release_buffer(pbuf); break; case PING_REPLY: // -------------------------------------- // answer received, signal waiting thread // -------------------------------------- os_signal(SIG_ICMP); break; } }
// IRS setup for dyads x op y // a is x, w is y // fs is the f field of the verb (the verb to be applied repeatedly) - or 0 if none // l, r are nominal ranks of fs // f2 is a setup verb (jtover, jtreshape, etc) A jtirs2(J jt,A a,A w,A fs,I l,I r,AF f2){A z;I af,ar,*old=jt->rank,rv[2],wf,wr; // push the jt->rank (pointer to ranks) stack. push/pop may not match, no problem RZ(a&&w); ar=AR(a); rv[0]=l=efr(ar,l); af=ar-l; // get rank, effective rank, length of frame... wr=AR(w); rv[1]=r=efr(wr,r); wf=wr-r; // ...for both args if(!(af||wf))R CALL2(f2,a,w,fs); // if no frame, call setup verb and return result ASSERT(!ICMP(AS(a),AS(w),MIN(af,wf)),EVLENGTH); // verify agreement /* if(af&&wf&&af!=wf)R rank2ex(a,w,fs,l,r,f2); */ jt->rank=rv; z=CALL2(f2,a,w,fs); jt->rank=old; // save ranks, call setup verb, pop rank stack // Not all setup verbs (*f2)() use the fs argument. R z; }
// ------------------------------------------------ // Function: ping_request() // ------------------------------------------------ // Input: IP address // Network interface ID // Output: - // ------------------------------------------------ // Description: Sends a ping request message // ------------------------------------------------ void ping_request(IPV4 ip, BYTE interface) { PPBUF buf; buf = ip_new(ip, 64, interface); if(buf == NULL) return; // --------------------- // assemble ICMP message // --------------------- IPH(buf->start)->prot = IP_PROT_ICMP; ICMP(buf->data)->type = PING_REQUEST; ICMP(buf->data)->code = 0; ICMP(buf->data)->checksum = 0; ICMP(buf->data)->id = random(); ICMP(buf->data)->seq = random(); buf->size = sizeof(ICMP_HDR); // ------------------ // calculate checksum // ------------------ icmp_checksum(buf->data, buf->size); ICMP(buf->data)->checksum = HTONS(~WORDOF(chk_H, chk_L)); // ----------------------------- // sends message to IP interface // ----------------------------- ip_send(buf); release_buffer(buf); }
static A jtmerge1(J jt,A w,A ind){A z;B*b;C*wc,*zc;D*wd,*zd;I c,it,j,k,m,r,*s,t,*u,*wi,*zi; RZ(w&&ind); r=MAX(0,AR(w)-1); s=1+AS(w); t=AT(w); k=bp(t); m=IC(w); c=aii(w); ASSERT(!(t&SPARSE),EVNONCE); ASSERT(r==AR(ind),EVRANK); ASSERT(!ICMP(s,AS(ind),r),EVLENGTH); GA(z,t,c,r,s); if(!(AT(ind)&B01+INT))RZ(ind=cvt(INT,ind)); it=AT(ind); u=AV(ind); b=(B*)u; ASSERT(!c||1<m||!(it&B01),EVINDEX); ASSERT(!c||1!=m||!memchr(b,C1,c),EVINDEX); zi=AV(z); zc=(C*)zi; zd=(D*)zc; wi=AV(w); wc=(C*)wi; wd=(D*)wc; switch(MCASE(it,k)){ case MCASE(B01,sizeof(C)): DO(c, *zc++=wc[*b++?i+c:i];); break; case MCASE(B01,sizeof(I)): DO(c, *zi++=wi[*b++?i+c:i];); break;
A jtirs2(J jt,A a,A w,A fs,I l,I r,AF f2) { A z; I af,ar,*old=jt->rank,rv[2],wf,wr; RZ(a&&w); ar=AR(a); rv[0]=l=efr(ar,l); af=ar-l; wr=AR(w); rv[1]=r=efr(wr,r); wf=wr-r; if(!(af||wf))R CALL2(f2,a,w,fs); ASSERT(!ICMP(AS(a),AS(w),MIN(af,wf)),EVLENGTH); /* if(af&&wf&&af!=wf)R rank2ex(a,w,fs,l,r,f2); */ jt->rank=rv; z=CALL2(f2,a,w,fs); jt->rank=old; R z; }
A jtrank2ex(J jt,A a,A w,A fs,I lr,I rr,AF f2) { PROLOG; A y,y0,ya,yw,z; B ab,b,wb; C*u,*uu,*v,*vv; I acn,acr,af,ak,ar,*as,at,k,mn,n=1,p,q,*s,wcn,wcr,wf,wk,wr,*ws,wt,yn,yr,*ys,yt; RZ(a&&w); at=AT(a); wt=AT(w); if(at&SPARSE||wt&SPARSE)R sprank2(a,w,fs,lr,rr,f2); ar=AR(a); as=AS(a); acr=efr(ar,lr); af=ar-acr; ab=ARELATIVE(a); wr=AR(w); ws=AS(w); wcr=efr(wr,rr); wf=wr-wcr; wb=ARELATIVE(w); if(!af&&!wf)R CALL2(f2,a,w,fs); RE(acn=prod(acr,as+af)); ak=acn*bp(at); u=CAV(a)-ak; NEWYA; RE(wcn=prod(wcr,ws+wf)); wk=wcn*bp(wt); v=CAV(w)-wk; NEWYW; b=af<=wf; p=b?wf:af; q=b?af:wf; s=b?ws:as; RE(mn=prod(p,s)); RE(n=prod(p-q,s+q)); ASSERT(!ICMP(as,ws,q),EVLENGTH); if(AN(a))MOVEYA else RZ(ya=reshape(vec(INT,acr,as+af),filler(a))); if(AN(w))MOVEYW else RZ(yw=reshape(vec(INT,wcr,ws+wf),filler(w))); #define VALENCE 2 #define TEMPLATE 0 #include "cr_t.h" }