Ejemplo n.º 1
0
int check_stdio_header(CcsImplHeader *hdr) {
  if (strncmp(REDIRECT_STDIO, hdr->handler, strlen(REDIRECT_STDIO))==0) {
    /*This is a request to make a duplicate to stdio*/
    if (stdio_alloc == 0) {
      stdio_alloc = 4096;
      stdio_buffer = (char*)malloc(stdio_alloc);
    }
    CcsServer_sendReply(hdr,0,0);
  }
  else if (strncmp(FETCH_STDIO, hdr->handler, strlen(FETCH_STDIO))==0) {
    /*Reply with the data loaded until now*/
    if (stdio_size > 0) {
      hdr->len = ChMessageInt_new(1); /* fake len to prevent socket closed without reply! */
      CcsServer_sendReply(hdr,stdio_size,stdio_buffer);
      stdio_size = 0;
    } else {
      if (stdio_waiting) {
        CcsServer_sendReply(&stdio_waiting_hdr,0,0);
      }
      stdio_waiting = 1;
      stdio_waiting_hdr = *hdr;
      stdio_waiting_hdr.len = ChMessageInt_new(1); /* fake len to prevent socket closed without reply! */
    }
  } else {
    return 0;
  }
  return 1;
}
Ejemplo n.º 2
0
/**
Send a Ccs reply back to the requestor, down the given socket.
Since there is no conv-host, node 0 does all the CCS 
communication-- this means all requests come to node 0
and are forwarded out; all replies are forwarded back to node 0.

Note: on Net- versions, CcsImpl_reply is implemented in machine.c
*/
void CcsImpl_reply(CcsImplHeader *rep,int repLen,const void *repData)
{
  const int repPE=0;
  rep->len=ChMessageInt_new(repLen);
  if (CmiMyPe()==repPE) {
    /*Actually deliver reply data*/
    CcsServer_sendReply(rep,repLen,repData);
  } else {
    /*Forward data & socket # to the replyPE*/
    int len=CmiReservedHeaderSize+
           sizeof(CcsImplHeader)+repLen;
    char *msg=CmiAlloc(len);
    char *r=msg+CmiReservedHeaderSize;
    *(CcsImplHeader *)r=*rep; r+=sizeof(CcsImplHeader);
    memcpy(r,repData,repLen);
    CmiSetHandler(msg,rep_fw_handler_idx);
    CmiSyncSendAndFree(repPE,len,msg);
  }
}
Ejemplo n.º 3
0
void write_stdio_duplicate(char* data) {
  if (stdio_alloc > 0) {
    int size = strlen(data);
    
    if (stdio_waiting) {
      stdio_waiting = 0;
      CcsServer_sendReply(&stdio_waiting_hdr,size+1,data);
    }
    else {
      if (size+stdio_size >= stdio_alloc) {
        char *newbuf;
        stdio_alloc += (size>4096 ? size : 4096);
        newbuf = (char*)malloc(stdio_alloc);
        memcpy(newbuf, stdio_buffer, stdio_size);
        free(stdio_buffer);
        stdio_buffer = newbuf;
      }
      strcpy(&stdio_buffer[stdio_size], data);
      stdio_size += size;
    }
  }
}