示例#1
0
文件: spawn.c 项目: MattWherry/yorick
static void
spawn_free(void *vproc)
{
  if (vproc) {
    spawn_proc *proc = vproc;
    spawn_proc *list = spawn_list;
    char *argv0 = proc->argv0;
    p_spawn_t *pp = proc->proc;
    proc->argv0 = 0;
    proc->proc = 0;
    p_free(argv0);
    if (pp) {
      p_send(pp, (char *)0, -9);
      p_spawf(pp, 0);
    }
    if (list == proc) {
      spawn_list = proc->next;
    } else while (list && list->next) {
      if (list->next == proc) {
        list->next = proc->next;
        break;
      }
      list = list->next;
    }
    p_free(proc);
  }
}
示例#2
0
文件: spawn.c 项目: MattWherry/yorick
/* send message or signal to process */
static void
spawn_eval(Operand *op)
{
  spawn_proc *proc = op->value;
  if (proc->proc) {
    int nargs = op->references;  /* (sic) misuse explained in ops3.c */
    Operand arg;
    Range *range;
    if (nargs!=1 || !yarg_op(0,&arg))
      YError("spawned process requires exactly one argument");
    range = (arg.ops==&rangeOps)? arg.value : 0;
    if (arg.ops!=&stringOps && arg.ops->typeID>T_LONG &&
        (!range || range->nilFlags!=(R_PSEUDO+R_MINNIL+R_MAXNIL)))
      YError("spawned process argument must be string or integer or -");
    if (arg.type.dims)
      YError("spawned process argument must be scalar");
    if (!proc->proc)
      YError("spawned process no longer exists");

    if (arg.ops == &stringOps) {
      /* send text message to process via its stdin */
      char *msg = *(char **)arg.value;
      if (msg && p_send(proc->proc, msg, strlen(msg)))
        YError("spawned process write to stdin failed");

    } else if (range) {
      /* suspend yorick virtual machine until callback from process */
      YError("(BUG) spawned process suspend not implemented");

    } else {
      /* send signal to process */
      long signum;
      arg.ops->ToLong(&arg);
      signum = *(long *)arg.value;
      p_send(proc->proc, (char *)0, -signum);
    }

  } else {
    YError("spawned process has no stdin");
  }

  Drop(1);
}
示例#3
0
文件: netops.c 项目: aep/libgit2
int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags)
{
	int ret;
	size_t off = 0;

#ifdef GIT_SSL
	if (socket->ssl.ctx)
		return gitno_send_ssl(&socket->ssl, msg, len, flags);
#endif

	while (off < len) {
		errno = 0;
		ret = p_send(socket->socket, msg + off, len - off, flags);
		if (ret < 0) {
			net_set_error("Error sending data");
			return -1;
		}

		off += ret;
	}

	return (int)off;
}