コード例 #1
0
ファイル: ua.c プロジェクト: pasichnichenko/baresip
/**
 * Reset the SIP transports for all User-Agents
 *
 * @param reg      True to reset registration
 * @param reinvite True to update active calls
 *
 * @return 0 if success, otherwise errorcode
 */
int uag_reset_transp(bool reg, bool reinvite)
{
	struct le *le;
	int err;

	/* Update SIP transports */
	sip_transp_flush(uag.sip);

	(void)net_check();
	err = ua_add_transp();
	if (err)
		return err;

	/* Re-REGISTER all User-Agents */
	for (le = uag.ual.head; le; le = le->next) {
		struct ua *ua = le->data;

		if (reg && ua->acc->regint) {
			err |= ua_register(ua);
		}

		/* update all active calls */
		if (reinvite) {
			struct le *lec;

			for (lec = ua->calls.head; lec; lec = lec->next) {
				struct call *call = lec->data;

				err |= call_reset_transp(call);
			}
		}
	}

	return err;
}
コード例 #2
0
ファイル: net.c プロジェクト: zhengxle/cyon
static int
net_send(struct connection *c)
{
	int			r;
	struct netbuf		*nb;
	u_int32_t		len;
	struct netcontext	*nctx = (struct netcontext *)c->nctx;

	while (!TAILQ_EMPTY(&(c->send_queue))) {
		nb = TAILQ_FIRST(&(c->send_queue));
		if (nb->b_len != 0) {
			len = MIN(NETBUF_SEND_PAYLOAD_MAX,
			    nb->b_len - nb->s_off);

			switch (c->l->type) {
			case EVENT_TYPE_INET_SOCKET:
				r = SSL_write(c->ssl,
				    (nb->buf + nb->s_off), len);
				break;
			case EVENT_TYPE_UNIX_SOCKET:
				r = write(c->fd, (nb->buf + nb->s_off), len);
				break;
			}

			cyon_debug("net_send(%d/%d bytes), progress with %d",
			    nb->s_off, nb->b_len, r);

			if (r <= 0 && c->l->type == EVENT_TYPE_INET_SOCKET) {
				if (!net_ssl_check(c, r, CONN_WRITE_POSSIBLE))
					return (CYON_RESULT_ERROR);
				if (!(c->flags & CONN_WRITE_POSSIBLE))
					return (CYON_RESULT_OK);
			}

			if (r == -1 && c->l->type == EVENT_TYPE_UNIX_SOCKET) {
				if (!net_check(c, CONN_WRITE_POSSIBLE))
					return (CYON_RESULT_ERROR);
				if (!(c->flags & CONN_WRITE_POSSIBLE))
					return (CYON_RESULT_OK);
			}

			if (r != -1)
				nb->s_off += (size_t)r;
		}

		if (nb->s_off == nb->b_len) {
			TAILQ_REMOVE(&(c->send_queue), nb, list);

			cyon_mem_free(nb->buf);
			pool_put(&(nctx->nb_pool), nb);
		}
	}

	return (CYON_RESULT_OK);
}
コード例 #3
0
ファイル: Net_Parse.cpp プロジェクト: CapCoder/FileCon
	bool Net_Parse::initial_net(string entry, bool active) {


		if (entry == "exit") {
			active = false;
			system("cls");
			return active;
		}
		else
		{
			net_check(entry);
			return true;
		}
	}
コード例 #4
0
ファイル: net.c プロジェクト: zhengxle/cyon
static int
net_recv(struct connection *c)
{
	int			r;
	struct netbuf		*nb;
	struct netcontext	*nctx = (struct netcontext *)c->nctx;

	while (!TAILQ_EMPTY(&(c->recv_queue))) {
		nb = TAILQ_FIRST(&(c->recv_queue));
		if (nb->cb == NULL) {
			cyon_debug("cyon_read_client(): nb->cb == NULL");
			return (CYON_RESULT_ERROR);
		}

again:
		switch (c->l->type) {
		case EVENT_TYPE_INET_SOCKET:
			r = SSL_read(c->ssl,
			    (nb->buf + nb->s_off), (nb->b_len - nb->s_off));
			break;
		case EVENT_TYPE_UNIX_SOCKET:
			r = read(c->fd,
			    (nb->buf + nb->s_off), (nb->b_len - nb->s_off));
			break;
		}

		cyon_debug("net_recv(%ld/%ld bytes), progress with %d",
		    nb->s_off, nb->b_len, r);

		if (r <= 0 && c->l->type == EVENT_TYPE_INET_SOCKET) {
			if (!net_ssl_check(c, r, CONN_READ_POSSIBLE))
				return (CYON_RESULT_ERROR);
			if (!(c->flags & CONN_READ_POSSIBLE))
				return (CYON_RESULT_OK);
		}

		if ((r == -1 || r == 0) &&
		    c->l->type == EVENT_TYPE_UNIX_SOCKET) {
			if (r == 0) {
				c->flags &= ~CONN_READ_POSSIBLE;
				return (CYON_RESULT_ERROR);
			}

			if (!net_check(c, CONN_READ_POSSIBLE))
				return (CYON_RESULT_ERROR);
			if (!(c->flags & CONN_READ_POSSIBLE))
				return (CYON_RESULT_OK);
		}

		if (r != -1)
			nb->s_off += (size_t)r;

		if (nb->s_off == nb->b_len) {
			r = nb->cb(nb);
			if (nb->s_off == nb->b_len) {
				TAILQ_REMOVE(&(c->recv_queue), nb, list);

				if (nb->flags & NETBUF_USE_OPPOOL)
					pool_put(&(nctx->op_pool), nb->buf);
				else
					cyon_mem_free(nb->buf);
				pool_put(&(nctx->nb_pool), nb);
			}

			if (r != CYON_RESULT_OK)
				return (r);

			if (nb->s_off != nb->b_len)
				goto again;
		}
	}

	return (CYON_RESULT_OK);
}