Ejemplo n.º 1
0
int swFactoryProcess_end(swFactory *factory, swDataHead *event)
{
	swServer *serv = factory->ptr;
	swEvent ev;
	bzero(&ev, sizeof(swEvent));

	ev.fd = event->fd;
	/**
	 * length == 0, close the connection
	 */
	ev.len = 0;

	/**
	 * passive or initiative
	 */
	ev.type = event->type;

	swConnection *conn = swServer_get_connection(serv, ev.fd);
	if (conn == NULL || conn->active == 0)
	{
		swWarn("can not close. Connection[%d] not found.", ev.fd);
		return SW_ERR;
	}
	event->from_id = conn->from_id;
	return swFactoryProcess_finish(factory, (swSendData *)&ev);
}
Ejemplo n.º 2
0
int swFactoryProcess_end(swFactory *factory, swDataHead *event)
{
	swServer *serv = factory->ptr;
	swSendData _send;

	bzero(&_send, sizeof(_send));

	_send.info.fd = event->fd;
	/**
	 * length == 0, close the connection
	 */
	_send.info.len = 0;

	/**
	 * passive or initiative
	 */
	_send.info.type = event->type;

	swConnection *conn = swServer_connection_get(serv, _send.info.fd);
	if (conn == NULL || conn->active == 0)
	{
		swWarn("can not close. Connection[%d] not found.", _send.info.fd);
		return SW_ERR;
	}
    if (serv->onClose != NULL)
    {
        serv->onClose(serv, event->fd, conn->from_id);
    }
	return swFactoryProcess_finish(factory, &_send);
}
Ejemplo n.º 3
0
/**
 * Close the connection
 */
int swFactoryProcess_end(swFactory *factory, int fd)
{
    swServer *serv = factory->ptr;
    swSendData _send;

    bzero(&_send, sizeof(_send));
    _send.info.fd = fd;
    _send.info.len = 0;
    _send.info.type = SW_EVENT_CLOSE;

    swConnection *conn = swServer_connection_get(serv, _send.info.fd);
    if (conn == NULL || conn->active == 0)
    {
        //swWarn("can not close. Connection[%d] not found.", _send.info.fd);
        return SW_ERR;
    }
    else if (conn->active & SW_STATE_CLOSEING)
    {
        swWarn("The connection[%d] is closeing.", fd);
        return SW_ERR;
    }
    else if (conn->active & SW_STATE_CLOSED)
    {
        return SW_ERR;
    }
    else
    {
        if (serv->onClose != NULL)
        {
            serv->onClose(serv, fd, conn->from_id);
        }
        conn->active |= SW_STATE_CLOSED;
        return swFactoryProcess_finish(factory, &_send);
    }
}
Ejemplo n.º 4
0
int swFactoryProcess_end(swFactory *factory, swDataHead *event)
{
	int ret;
	swFactoryProcess *object = factory->object;
	swServer *serv = factory->ptr;
	swEvent ev;

	bzero(&ev, sizeof(swEvent));
	ev.fd = event->fd;
	ev.len = 0; //len=0表示关闭此连接
	ev.from_id = SW_CLOSE_NOTIFY;
	ret = swFactoryProcess_finish(factory, (swSendData *)&ev);
	serv->onClose(serv, event->fd, event->from_id);
	return ret;
}
Ejemplo n.º 5
0
int swFactoryProcess_end(swFactory *factory, swDataHead *event)
{
	int ret;
	swServer *serv = factory->ptr;
	swEvent ev;

	bzero(&ev, sizeof(swEvent));
	ev.fd = event->fd;
	ev.len = 0; //len=0表示关闭此连接
	ev.type = SW_EVENT_CLOSE;
	ret = swFactoryProcess_finish(factory, (swSendData *)&ev);
	if (serv->onClose != NULL)
	{
		serv->onClose(serv, event->fd, event->from_id);
	}
	return ret;
}