Exemplo n.º 1
0
int gitno_recv(gitno_buffer *buf)
{
	int ret;

#ifdef GIT_SSL
	if (buf->ssl != NULL) {
		if ((ret = ssl_recv(buf->ssl, buf->data + buf->offset, buf->len - buf->offset)) < 0)
			return -1;
	} else {
		ret = p_recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0);
		if (ret < 0) {
			net_set_error("Error receiving socket data");
			return -1;
		}
	}
#else
	ret = p_recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0);
	if (ret < 0) {
		net_set_error("Error receiving socket data");
		return -1;
	}
#endif

	buf->offset += ret;
	return ret;
}
Exemplo n.º 2
0
Arquivo: netops.c Projeto: aep/libgit2
static int gitno__recv(gitno_buffer *buf)
{
	int ret;

	ret = p_recv(buf->socket->socket, buf->data + buf->offset, buf->len - buf->offset, 0);
	if (ret < 0) {
		net_set_error("Error receiving socket data");
		return -1;
	}

	buf->offset += ret;
	return ret;
}
Exemplo n.º 3
0
/* do interpreted callback to process message from process */
static void
spawn_callback(void *vproc, int err)
{
  spawn_proc *proc = vproc;
  char *msg = 0;
  Array *msga;
  Instruction code[12];
  Symbol *ctable;
  long callback = -1;
  if (err != 2) {
    long nbytes = 0;
    if (proc && proc->proc) callback = err? proc->callerr : proc->callout;
    if (callback<0) {
      /* probably a bug, but unclear that calling YError
       * would prevent the possible fault loop
       */
      return;
    }

    /* read the message from process
     * - this just reads all available bytes, up to 2048
     */
    msg = p_malloc(2048);
    nbytes = p_recv(proc->proc, msg, 2048);
    if (nbytes <= 0) {
      p_free(msg);
      /* can get this when an unrelated process finishes, just ignore */
      /* YError("spawn process read error in callback"); */
      /* also could get this if the fd gave POLLERR, possibly should
       * find some way to figure out what's going on
       */
      return;
    }
    msg = p_realloc(msg, nbytes+1);
    msg[nbytes] ='\0';
  } else {
    if (!proc || proc->callout<0) return;
    callback = proc->callout;
    proc->callout = -1;
    p_spawf(proc->proc, 1);
    proc->proc = 0;
  }

  if (callback < 0) return;

  /* task constant table contains only message string */
  msga = NewArray(&stringStruct, (Dimension *)0);
  msga->value.q[0] = msg;
  ctable = p_malloc(sizeof(Symbol));
  ctable->ops = &dataBlockSym;
  ctable->value.db = (DataBlock *)msga;

  /* fill in function code */
  code[0].Action = &PushVariable;
  code[1].index = callback;
  code[2].Action = &PushString;
  code[3].constant = ctable;
  code[4].Action = &Eval;
  code[5].count = 1;
  code[6].Action = &DropTop;
  code[7].Action = &PushNil;
  code[8].Action = &Return;
  code[9].Action = 0;
  code[10].index = 11;
  /* NewFunction moves this to beginning */
  code[11].index = Globalize("*callback*", 0L);
  PushTask(NewFunction(ctable, 1, 0, 0, 0, 0, 2, code, 11));
}