示例#1
0
文件: handle.cpp 项目: bratkov/tmos
void CHandle::drv_write(const void * buf, unsigned int l)
{
	if(res < FLG_BUSY)
	{
		//handle is idle and open
		len = l;
		set_res_cmd(CMD_WRITE);
		src.as_cvoidptr = buf;
		svc_drv_service(this);
	}
}
示例#2
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Locked command
 * @param c
 * @param ptr
 * @return
 */
RES_CODE CHandle::tsk_command_locked(void * c, void *ptr)
{
	if(!complete())
		return (res);

	//handle is idle and open
	set_res_cmd(CMD_COMMAND|FLAG_LOCK);
	dst.as_voidptr = ptr;
	src.as_voidptr = c;
	return (tsk_start_and_wait());
}
示例#3
0
文件: handle.cpp 项目: bratkov/tmos
/**
 *
 * @param cmd
 * @param par
 * @param ptr
 * @return
 */
RES_CODE CHandle::tsk_command(unsigned int c, void * par, void *ptr)
{
	if(!complete())
		return (res);

	//handle is idle and open
	set_res_cmd(c);
	dst.as_voidptr = ptr;
	src.as_voidptr = par;
	return (tsk_start_and_wait());
}
示例#4
0
文件: handle.cpp 项目: bratkov/tmos
void CHandle::drv_read(void * buf, unsigned int l)
{
	if(res < FLG_BUSY)
	{
		//handle is idle and open
		len = l;
		set_res_cmd(CMD_READ);
		dst.as_voidptr = buf;
		svc_drv_service(this);
	}
}
示例#5
0
RES_CODE CSocket::gethostbyname(CSTRING& ip_adr, const char* url)
{
	if(complete())
	{
		src.as_charptr = (char*) url;
		dst.as_voidptr = &ip_adr;
		set_res_cmd(SOCK_CMD_GET_HOST);
		tsk_start_and_wait();
	}
	return (res);
}
示例#6
0
/**
 * Associate a socket with a port and address.
 * @param ip_adr
 * @param port
 * @return RES_OK on success
 */
RES_CODE CSocket::bind(unsigned int ip_adr, unsigned int port)
{
	if(complete())
	{
		src.as_int = ip_adr;
		dst.as_int = port;
		set_res_cmd(SOCK_CMD_BIND_ADR);
		tsk_start_and_wait();
	}
	return (res);
}
示例#7
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Blocking locked read
 * @param buf
 * @param l
 * @return
 */
RES_CODE CHandle::tsk_read_locked(void * buf, unsigned int l)
{
	if(!complete())
		return (res);

	//handle is idle and open
	len = l;
	set_res_cmd((CMD_READ|FLAG_LOCK));
	dst.as_voidptr = buf;
	return (tsk_start_and_wait());
}
示例#8
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Blocking locked write
 * @param buf
 * @param l
 * @return
 */
RES_CODE CHandle::tsk_write_locked(const void * buf, unsigned int l)
{
	if(!complete())
		return (res);

	//handle is idle and open
	len = l;
	set_res_cmd(CMD_WRITE|FLAG_LOCK);
	src.as_voidptr = (void*)buf;
	return (tsk_start_and_wait());
}
示例#9
0
RES_CODE CSocket::get_addr(unsigned int& ip_adr, unsigned short& port, int local)
{
	if(complete())
	{
		src.as_intptr = &ip_adr;
		dst.as_shortptr = &port;
		len = local;
		set_res_cmd(SOCK_CMD_GET_ADDR);
		tsk_start_and_wait();
	}
	return (res);
}
示例#10
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Start command
 * @param c
 * @param ptr
 * @return
 */
bool CHandle::tsk_start_command(void * c, void *ptr)
{
	if(!complete())
		return (false);

	//handle is idle and open
	set_res_cmd(CMD_COMMAND);
	dst.as_voidptr = ptr;
	src.as_voidptr = c;
	tsk_start_handle();
	return (true);
}
示例#11
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Read & write (swap) operation
 * @param d
 * @param s
 * @param l
 * @return
 */
RES_CODE CHandle::tsk_read_write(void *d, const void *s, unsigned int l)
{
	if(!complete())
		return (res);

	//handle is idle and open
	len = l;
	set_res_cmd(CMD_READ_WRITE);
	dst.as_voidptr = d;
	src.as_voidptr = (void*)s;
	return (tsk_start_and_wait());
}
示例#12
0
文件: handle.cpp 项目: bratkov/tmos
void CHandle::drv_read_write(void *d, const void *s, unsigned int l)
{
	if(res < FLG_BUSY)
	{
		//handle is idle and open
		len = l;
		set_res_cmd(CMD_READ_WRITE);
		dst.as_voidptr = d;
		src.as_cvoidptr = s;
		svc_drv_service(this);
	}
}
示例#13
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Start write
 * @param buf
 * @param l
 * @return
 */
bool CHandle::tsk_start_write(const void * buf, unsigned int l)
{
	if(!complete())
		return (false);

	//handle is idle and open
	len = l;
	set_res_cmd(CMD_WRITE);
	src.as_voidptr = (void*)buf;
	tsk_start_handle();
	return (true);
}
示例#14
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Start read operation
 * @param buf
 * @param l
 * @return
 */
bool CHandle::tsk_start_read(void * buf, unsigned int l)
{
	if(!complete())
		return (false);

	//handle is idle and open
	len = l;
	set_res_cmd(CMD_READ);
	dst.as_voidptr = buf;
	tsk_start_handle();
	return (true);
}
示例#15
0
/**
 * 	“One-way” close of a socket
 * @return
 */
RES_CODE CSocket::close()
{
	if(res < RES_CLOSED)
	{
		if(complete())
		{
			set_res_cmd(SOCK_CMD_CLOSE);
			tsk_start_and_wait();
		}
		CHandle::close();
	}
	return (res);
}
示例#16
0
/**
 * Disconnect a connection from a remote url.
 * @return
 */
NET_CODE CSocket::disconnect(void)
{
	NET_CODE result = NET_IDLE;

	if(complete())
	{
		set_res_cmd(SOCK_CMD_DISCONNECT);
		tsk_start_and_wait();
		if(res == RES_OK)
			result = NET_OK;
		else
			result = error;
	}
	return (result);
}
示例#17
0
/**
 * Initiate a connection to a remote port and address.
 * @param ip_adr
 * @param port
 * @return
 */
NET_CODE CSocket::connect(const char* ip_adr, unsigned int port)
{
	NET_CODE result = NET_IDLE;

	if(complete())
	{
		src.as_charptr = (char*) ip_adr;
		dst.as_int = port;
		set_res_cmd(SOCK_CMD_CONNECT_ADR);
		tsk_start_and_wait();
		if(res == RES_OK)
			result = NET_OK;
		else
			result = error;
	}
	return (result);
}
示例#18
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Resume write operation
 * @param buf
 * @param l
 * @return
 */
RES_CODE CHandle::tsk_resume_write(const void * buf, unsigned int l)
{
	if(complete())
	{
		//handle is idle and open
		len = l;
		set_res_cmd(CMD_WRITE);
		src.as_voidptr = (void*)buf;
	    tsk_start_handle();
	    if(tsk_resume_wait_signal(signal))
	        res &= ~FLG_SIGNALED;
	    else
	    	tsk_cancel();
	}

    return (res);
}
示例#19
0
/**
 * Accept a connection request.
 * @param timeout
 * @return
 */
NET_CODE CSocket::accept(CSocket* new_sock, unsigned int timeout)
{
	if(complete())
	{
		dst.as_voidptr = new_sock;
		set_res_cmd(SOCK_CMD_ACCEPT);
	    tsk_start_handle();
	    if(tsk_wait_signal(signal, timeout))
	    {
	        res &= ~FLG_SIGNALED;
	    }
	    else
	    	tsk_cancel();

	}
	return (res);
}
示例#20
0
文件: handle.cpp 项目: bratkov/tmos
/**
 * Time limited locked read
 * @param buf
 * @param l
 * @param time
 * @return
 */
RES_CODE CHandle::tsk_read_locked(void * buf, unsigned int l, unsigned int time)
{
	if(complete())
	{
		//handle is idle and open
		len = l;
		set_res_cmd((CMD_READ|FLAG_LOCK));
		dst.as_voidptr = buf;
	    tsk_start_handle();
	    if(tsk_wait_signal(signal, time))
	        res &= ~FLG_SIGNALED;
	    else
	    	tsk_cancel();
	}

    return (res);
}
示例#21
0
/**
 * Initiate a connection to a remote link.
 * @param link
 * @return
 */
NET_CODE CSocket::connect(const CURL& link)
{
	NET_CODE result = NET_IDLE;

	if(complete())
	{
		src.as_ccharptr = link.host.c_str();
		dst.as_int = link.port;
		set_res_cmd(SOCK_CMD_CONNECT_URL);
		tsk_start_and_wait();
		if(res == RES_OK)
			result = NET_OK;
		else
			result = error;
	}
	return (result);
}
示例#22
0
NET_CODE CSocket::open(const sock_mode_t* smode)
{
	if(!this)
		return NET_ERR_OUT_OF_MEMORY;

	tsk_open(smode->driver, smode);
	if(RES_OK == res)
	{
		set_res_cmd(SOCK_CMD_OPEN);
		tsk_start_and_wait();
		if(res == RES_OK)
		{
			return NET_OK;
		} else
		{
			CHandle::close();
		}
	}
	else
		error = NET_ERR_HANDLE_OPEN;
	return error;
}
示例#23
0
/**
 * Associate a socket with an URL
 * @param url
 * @return RES_OK on success
 */
RES_CODE CSocket::bind(const char* url)
{
	NET_CODE result = NET_IDLE;
	if(complete())
	{
		CURL link;

		result = link.url_parse(url);
		if(result == RES_OK)
		{
			src.as_ccharptr = link.host.c_str();
			dst.as_int = link.port;
			set_res_cmd(SOCK_CMD_BIND_URL);
			tsk_start_and_wait();
			if(res == RES_OK)
				result = NET_OK;
			else
				result = error;
		}
	}
	return (result);
}