Esempio n. 1
0
int lwip_sock_read(void *conn, unsigned char *buff, unsigned long len) {
	struct netbuf *new_buf=0;
	unsigned char *data;
	int data_len=0;
	int ret,newret;

	SYSCALL_DEBUG(" SOCK read :%x len:%d \n",buff,len);
	mutexLock(g_netBH_lock);
	ret=netconn_recv(conn, &new_buf);
	mutexUnLock(g_netBH_lock);

	if (ret!=ERR_OK){
		SYSCALL_DEBUG(" Fail to recv data: %x newret:%x(%d) \n",ret,-ret,-ret);
		return 0;
	}

	netbuf_data(new_buf,&data,&data_len);
	SYSCALL_DEBUG(" SUCESS to recv data:%d  ret:%d\n",data_len,ret);
	if (data_len >  0){
		ut_memcpy(buff,data,ut_min(data_len,len));
		ret = ut_min(data_len,len);
	}else{
		ret = 0;
	}

	mutexLock(g_netBH_lock);
	netbuf_delete(new_buf);
	mutexUnLock(g_netBH_lock);

	return ret;
}
Esempio n. 2
0
static void netfront_input(struct netif *netif, unsigned char* data, int len) {
	struct eth_hdr *ethhdr;
	struct pbuf *p, *q;
	int ret;

#if ETH_PAD_SIZE
	len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif

	/* move received packet into a new pbuf */
	mutexLock(g_netBH_lock);
	p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
	mutexUnLock(g_netBH_lock);
	if (p == NULL) {
		LINK_STATS_INC(link.memerr);
		LINK_STATS_INC(link.drop);
		error_mem++;
		return;
	}

#if ETH_PAD_SIZE
	pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif

	/* We iterate over the pbuf chain until we have read the entire
	 * packet into the pbuf. */
	for (q = p; q != NULL && len > 0; q = q->next) {
		/* Read enough bytes to fill this pbuf in the chain. The
		 * available data in the pbuf is given by the q->len
		 * variable. */
		ut_memcpy(q->payload, data, len < q->len ? len : q->len);
		data += q->len;
		len -= q->len;
	}

#if ETH_PAD_SIZE
	pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif

	LINK_STATS_INC(link.recv);

	/* points to packet payload, which starts with an Ethernet header */
	ethhdr = p->payload;

	mutexLock(g_netBH_lock);
	if (ethernet_input(p, netif) != ERR_OK){
		BUG();
		pbuf_free(p);
	}
	mutexUnLock(g_netBH_lock);
}
Esempio n. 3
0
int mmapLogReadLine(char *buffer, uint16_t len)
{
    MMAP_FILE_HEADER *hd;
    char *mdata;
    unsigned long rpos;
    int rlen;
    mutexLock(g_mmap_log.mutex, -1);
    hd = (MMAP_FILE_HEADER*)g_mmap_log.handle->data;
    mdata = (char*)g_mmap_log.handle->data;
    rpos = g_mmap_log.readpos;
    if(rpos == hd->writepos)
        rlen = -2;
    else
    {
        if(hd->endpos > hd->writepos && rpos >= hd->endpos)
            rpos = g_mmap_log.readpos = sizeof(MMAP_FILE_HEADER);

        rlen = *((uint16_t*)(mdata + rpos));
    }

    if(rlen > 0 && len > rlen)
    {
        memcpy_s(buffer, len, mdata + rpos + sizeof(uint16_t), rlen);
        rpos += (rlen + sizeof(uint16_t));
        g_mmap_log.readpos = rpos;
    }
    else if(rlen > 0)
        rlen = -1;

    mutexUnLock(g_mmap_log.mutex);

    return rlen;
}
Esempio n. 4
0
/**
 * Returns the current quit state
 * @return 					- quit state (true if application should be terminated)
 */
BOOL ressourcesGetQuitState()
{
	int result;
	mutexLock(&clientMutex);
	result = clientQuitState;
	mutexUnLock(&clientMutex);
	return result;
}
Esempio n. 5
0
/**
 * Returns the current game stage
 * @return 					- game stage  ( PLAYER_STAGE_PREPARATION or PLAYER_STAGE_PLAYING )
 */
int ressourcesGetStage()
{
	int result;
	mutexLock(&clientMutex);
	result = clientStage;
	mutexUnLock(&clientMutex);
	return result;
}
Esempio n. 6
0
int lwip_sock_connect(void *conn, unsigned long *addr, uint16_t port) {
	int ret;

	mutexLock(g_netBH_lock);
	ret = netconn_connect(conn, addr, lwip_ntohs(port));
	mutexUnLock(g_netBH_lock);
	return ret;
}
Esempio n. 7
0
/**
 * Returns the current player id
 * @return 					- player id( 0 - 5 )
 */
int ressourcesGetPlayerID()
{
	int result;
	mutexLock(&clientMutex);
	result = clientPlayerId;
	mutexUnLock(&clientMutex);
	return result;
}
Esempio n. 8
0
/**
 * Returns the current socket file descriptor for the client
 * @return 					- socket file descriptor
 */
int ressourcesGetSocket()
{
	int result;
	mutexLock(&clientMutex);
	result = clientSocket;
	if (result == -1)
		syslogWrite(lerror, "ressourcesGetSocket: no socket available");

	mutexUnLock(&clientMutex);
	return result;
}
Esempio n. 9
0
int lwip_sock_read_from(void *conn, unsigned char *buff, unsigned long len,struct sockaddr *sockaddr, int addr_len) {
	struct netbuf *new_buf=0;
	unsigned char *data;
	int data_len=0;
	int ret=0;

	SYSCALL_DEBUG(" SOCK recvfrom :%x len:%d \n",buff,len);

	mutexLock(g_netBH_lock);
	ret=netconn_recv(conn,  &new_buf);
	mutexUnLock(g_netBH_lock);
if (ret == ERR_TIMEOUT){
	if (g_current_task->killed == 1){
		return 0;
	}
}

	if (ret!=ERR_OK){
		SYSCALL_DEBUG(" Fail to recvfrom data: %x newret:%x(%d) \n",ret,-ret,-ret);
		return 0;
	}
	SYSCALL_DEBUG(" SUCESS to recv data:%d \n",ret);
	netbuf_data(new_buf,&data,&data_len);
	if (data_len >  0){
		if (sockaddr != 0){
			sockaddr->addr = new_buf->addr.addr;
			sockaddr->sin_port = new_buf->port;
		}
		ut_memcpy(buff,data,ut_min(data_len,len));
		ret = ut_min(data_len,len);
	}else{
		ret =0;
	}

	mutexLock(g_netBH_lock);
	netbuf_delete(new_buf);
	mutexUnLock(g_netBH_lock);

	return ret;
}
Esempio n. 10
0
void *lwip_sock_open(int type) {
	void *ret;

	mutexLock(g_netBH_lock);
	if (type == SOCK_DGRAM) {
		ret = netconn_new(NETCONN_UDP);
	} else if (type == SOCK_STREAM ) {
		ret = netconn_new(NETCONN_TCP);
	} else {
		SYSCALL_DEBUG("Error socket Unknown type : %d \n",type);
		ret = 0;
	}
	mutexUnLock(g_netBH_lock);
	return ret;
}
Esempio n. 11
0
void logInit(int logType, const char* lpszPath)
{
#if !defined(ENABLE_DMLOG)
	return;
#else
    if(g_logInited)
        return;

    g_logLevel = logDebugLevel;
    if(logType < LOG_DRIVER_MAX)
        g_logType = logType;
	InitLock(&g_LockLog);
    g_hLogFile = NULL;
    g_logInited = 1;

    if(g_logType == LOG_DRIVER_FILE)
    {
	    g_hLogFile = fopen(lpszPath, "w+t");
    }
    else if(g_logType == LOG_DRIVER_MMAP)
    {
        g_mmap_log.event = eventNew(NAMED_EVENT_PATH);
        g_mmap_log.mutex = mutexNew(NAMED_MUTEX_PATH);
        g_mmap_log.handle = mmapOpen(NAMED_MMAP_PATH, MMAP_LOG_FILE_SIZE);

        do{
            MMAP_FILE_HEADER *hd;
            mutexLock(g_mmap_log.mutex, -1);
            g_mmap_log.readpos = sizeof(MMAP_FILE_HEADER);
            hd = (MMAP_FILE_HEADER*)g_mmap_log.handle->data;
            if(hd->magic_code != LOG_MMAP_MAGIC_CODE){
                printf("It is the first process to create the memory map!\r\n");
                hd->magic_code = LOG_MMAP_MAGIC_CODE;
                hd->writepos = sizeof(MMAP_FILE_HEADER);
                hd->endpos = sizeof(MMAP_FILE_HEADER);
            }
            mutexUnLock(g_mmap_log.mutex);
        }while(0);
    }
    else if(g_logType == LOG_DRIVER_SYSLOG)
    {
      #ifdef LINUX
        openlog(NULL, LOG_CONS|LOG_PID, LOG_USER);
      #endif
    }
#endif
}
Esempio n. 12
0
int mmapLogWrite(const char *buffer, uint16_t len)
{
    MMAP_FILE_HEADER *hd;
    char *mdata;
    mutexLock(g_mmap_log.mutex, -1);
    hd = (MMAP_FILE_HEADER*)g_mmap_log.handle->data;
    mdata = (char*)g_mmap_log.handle->data;
    if(len + hd->writepos + sizeof(uint16_t) > g_mmap_log.handle->size)    //We now rotate
    {
        hd->endpos = hd->writepos;
        hd->writepos = sizeof(MMAP_FILE_HEADER);
    }
    *((short*)(mdata + hd->writepos)) = len;
    memcpy_s(mdata + hd->writepos + sizeof(uint16_t), g_mmap_log.handle->size, buffer, len);
    hd->writepos += len + sizeof(uint16_t);
    if(hd->writepos + 4096 > hd->endpos)
        hd->endpos = sizeof(MMAP_FILE_HEADER);
    mutexUnLock(g_mmap_log.mutex);
    eventSignal(g_mmap_log.event);

    return len;
}
Esempio n. 13
0
/**
 * Sets the the current quit state
 * @param newState	        - new quit state
 * @param callQuit	        - call quiQuit() to terminate GUI-Loop
 * @return 					- none
 */
void ressourcesSetQuitState(BOOL newState, BOOL callQuit)
{
	mutexLock(&clientMutex);
	if (newState)
	{
		if (newState != clientQuitState)
		{
			if (callQuit)
				guiQuit();
			syslogWrite(ldebug, "ressourcesSetQuitState: Setting Quit state to true");
		}
		else
		{
			syslogWrite(lerror, "ressourcesSetQuitState: ERROR Quit state already set to true!");
		}
	}
	else
	{
		syslogWrite(ldebug, "ressourcesSetQuitState: Setting Quit state to false");
	}
	clientQuitState = newState;
	mutexUnLock(&clientMutex);
}
Esempio n. 14
0
/**
 * Sets the socket for the client
 * @param socket	        - new socket file descriptor
 * @return 					- none
 */
void ressourcesSetSocket(int socket)
{
	mutexLock(&clientMutex);
	clientSocket = socket;
	mutexUnLock(&clientMutex);
}
Esempio n. 15
0
/**
 * Sets a new player id
 * @param id		        - new player id( 0 - 5 )
 * @return 					- none
 */
void ressourcesSetPlayerID(int id)
{
	mutexLock(&clientMutex);
	clientPlayerId = id;
	mutexUnLock(&clientMutex);
}
Esempio n. 16
0
/**
 * userdataUnlock() \n
 * Function to unlock mutex \n
 * @return true or false \n
 */
BOOL userdataUnlock()
{
	return mutexUnLock((MUTEX *)userdataMutex(getMutex));
}
Esempio n. 17
0
/**
 * Sets a new game stage ( PLAYER_STAGE_PREPARATION or PLAYER_STAGE_PLAYING )
 * @param newStage	        - dummy parameter(only necessary to prevent stack corruption)
 * @return 					- none
 */
void ressourcesSetStage(int newStage)
{
	mutexLock(&clientMutex);
	clientStage = newStage;
	mutexUnLock(&clientMutex);
}