当前位置: 首页>>代码示例>>C++>>正文


C++ SDLNet_CheckSockets函数代码示例

本文整理汇总了C++中SDLNet_CheckSockets函数的典型用法代码示例。如果您正苦于以下问题:C++ SDLNet_CheckSockets函数的具体用法?C++ SDLNet_CheckSockets怎么用?C++ SDLNet_CheckSockets使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDLNet_CheckSockets函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

void IRC::step(void)
{
	if (!socket)
		return;

	while (1)
	{
		int check = SDLNet_CheckSockets(socketSet, 0);
		if (check == 0)
		{
			break;
		}
		else if (check == 1)
		{
			char data[IRC_MESSAGE_SIZE];
			bool res=getString(data);
			if (res)
			{
				if (verbose)
					printf("YOG (IRC) has received [%s]\n", data);
				interpreteIRCMessage(data);
			}
			else
			{
				printf("YOG (IRC) has received an error\n");
				break;
			}
		}
		else
		{
			printf("YOG (IRC) has a select error\n");
			break;
		}
	}
}
开发者ID:krichter722,项目名称:glob2-git-hg,代码行数:35,代码来源:IRC.cpp

示例2: SDL_LockMutex

    int Connection::recvWait(inp::INFPacket& dest, Uint32 ms){
        SDL_LockMutex(pimpl_->dataAccess);
        if( (pimpl_->group == NULL) || (pimpl_->userSocket == NULL)  )
        {
            pimpl_->connectTime = 0;
            SDL_UnlockMutex(pimpl_->dataAccess);
            return -1;
        }

        Uint32 startTime = SDL_GetTicks();
        int numReady;
        while( (SDL_GetTicks()-startTime) < ms ){
            numReady = SDLNet_CheckSockets(pimpl_->group, 10);
            if( numReady == -1 ){
                pimpl_->active = false;
                pimpl_->connectTime = 0;
                break;
            }
            if( SDLNet_SocketReady(pimpl_->userSocket) ){
                pimpl_->active = true;
                SDL_UnlockMutex(pimpl_->dataAccess);
                return recv(dest);
            }
        }
        SDL_UnlockMutex(pimpl_->dataAccess);
        return -1;
    }
开发者ID:Infraelly,项目名称:old-infraelly-engine,代码行数:27,代码来源:Connection.cpp

示例3: get_server_message

/* check if there's a message from the server */
void get_server_message () {
  int nr_active_sock, reclen, startptr = 0, msglen;

try_again:
  nr_active_sock = SDLNet_CheckSockets (theset, 1);
  if (nr_active_sock == 0) return;
  if (!SDLNet_SocketReady (thesock)) return;

  reclen = get_packet ();
  if (reclen == -1) return;
  if (reclen <= 0) {
    log_error ("Disconnected by the server!\n");
    exit_connection (EXIT_ALL);
    exit (1);
  }

  msglen = *((short *) (msgbuf + startptr + 1));
  msglen += 2;
  if (process_message(msgbuf+startptr, msglen) == 0) {
    /* something went wrong when processing our message. Log out. */
    exit_connection (EXIT_ALL);
    log_error ("Unable to process message");
    exit (1);
  }

  goto try_again;
}
开发者ID:BackupTheBerlios,项目名称:redknight,代码行数:28,代码来源:connection.c

示例4: SDLNet_CheckSockets

void Users::process(){
    int n = SDLNet_CheckSockets(set, 0);
    if (n < 1) return;

    if (SDLNet_SocketReady(sock)){
        printf("new user...\n");
        TCPsocket newuser = SDLNet_TCP_Accept(sock);

        printf("Accepted...\n");
        User *u = new User(newuser);
        push_back(u);
        SDLNet_TCP_AddSocket(set,newuser);
    }

    User *u;
    for( iterator i = begin(); i != end(); i++ ){
        u = *i;
        if (SDLNet_SocketReady(u->sock)){
            int len;
            char buf[MAXLEN];
            if ((len = readLine(u->sock,buf,sizeof(buf))) > 0){
                fprintf(stderr,"got len=%d text from '%s': '%s'\n",len,u->name,buf);
                handle_command(buf,u);
            } else {
                printf("dead connection\n");
                SDLNet_TCP_DelSocket(set, u->sock);
                SDLNet_TCP_Close(u->sock);
                i = erase(i);
            }
        }
    }
}
开发者ID:qartis,项目名称:qonk,代码行数:32,代码来源:network.cpp

示例5: while

	  int TCP_RECEIVEOBJ::read_tcp(char * readbuf, int size)
	  {
		int len;
		bool reading=true;	
		char tempbuf[readbuflength];

		reading=true;
		readbuf[0]=0;
		while (reading)
		{
			if (SDLNet_CheckSockets(set, sockettimeout) == -1)  return(TCP_BAD_REQUEST);
				
			if (SDLNet_SocketReady(sock))
			{
				if ((len = SDLNet_TCP_Recv(sock, tempbuf, size)) <= 0) return(TCP_ERROR);
				
				tempbuf[len] = '\0';
				if (strlen(readbuf) + strlen(tempbuf) <= (unsigned int)size) strcat (readbuf, tempbuf);
				if (strlen(readbuf)>=(unsigned int)size) reading=false;
			}
			else reading=false;
		
		}
		cout << readbuf;
	    return (TCP_OK);
	  }
开发者ID:Smeetal,项目名称:BrainBay,代码行数:26,代码来源:ob_tcp_receive.cpp

示例6: snCheckSockets

static __inline__ int snCheckSockets(SDLNet_SocketSet ss, int wait)
{
  int val = 0;

  val = SDLNet_CheckSockets(ss, wait);
  return val;
}
开发者ID:PerudOnLan,项目名称:PerudOnLan,代码行数:7,代码来源:net2.c

示例7: FCEUD_GetDataFromServer

int FCEUD_GetDataFromServer(uint8 *data)
{
  uint8 buf[128];    
  NoWaiting&=~2;

  while(SDLNet_CheckSockets(set,1)==0)
  {
   // do something here.
  }
  if(SDLNet_SocketReady(Socket))
  {
     if(de32(buf)==incounter) /* New packet, keep. */
     {
      unsigned long beefie; 
      memcpy(data,buf+TCPHEADSIZE,5);
      incounter++;
      
      if(!ioctl(Socket,FIONREAD,&beefie))
       if(beefie)
        NoWaiting|=2;
       
      return(1);
     }

  }
  if(SDLNet_SocketReady(UDPSocket)
  {


  }
}
开发者ID:Plombo,项目名称:fceux,代码行数:31,代码来源:sdl-netplay.cpp

示例8: fprintf

bool ClientConnection::poll(packet_recv_callback message_handler, void* context,
		int timeout) {
	if (_client_socket == NULL) {
		fprintf(stderr,
				"ClientConnection::poll: Connection not initialized!\n");
		return false;
	}

	while (true) {
		int nready = SDLNet_CheckSockets(_socket_set, timeout);
		timeout = 0; // Don't wait again on repeated checks
		if (nready < 0) {
			fprintf(stderr, "Error: SDLNet_CheckSockets reported %s\n",
					SDLNet_GetError());
			return false;
		} else if (nready == 0) {
			break;
		}
		while (SDLNet_SocketReady(_client_socket)) {
			receiver_t receiver, sender;
			receive_packet(_client_socket, _packet_buffer, receiver, sender);
			if (message_handler && !_packet_buffer.empty()) {
				message_handler(sender, context, &_packet_buffer[HEADER_SIZE],
						_packet_buffer.size() - HEADER_SIZE);
			}
		}
	}
	return true;
}
开发者ID:Zolomon,项目名称:lanarts,代码行数:29,代码来源:ClientConnection.cpp

示例9: receive_thread_function

// ZZZ: the socket listening thread loops in this function.  It calls the registered
// packet handler when it gets something.
static int
receive_thread_function(void*) {
    while(true) {
        // We listen with a timeout so we can shut ourselves down when needed.
        int theResult = SDLNet_CheckSockets(sSocketSet, 1000);
        
        if(!sKeepListening)
            break;
        
        if(theResult > 0) {
            theResult = SDLNet_UDP_Recv(sSocket, sUDPPacketBuffer);
            if(theResult > 0) {
                if(take_mytm_mutex()) {
                    ddpPacketBuffer.protocolType	= kPROTOCOL_TYPE;
                    ddpPacketBuffer.sourceAddress	= sUDPPacketBuffer->address;
                    ddpPacketBuffer.datagramSize	= sUDPPacketBuffer->len;
                    
                    // Hope the other guy is done using whatever's in there!
                    // (As I recall, all uses happen in sPacketHandler and its progeny, so we should be fine.)
                    memcpy(ddpPacketBuffer.datagramData, sUDPPacketBuffer->data, sUDPPacketBuffer->len);
                    
                    sPacketHandler(&ddpPacketBuffer);
                    
                    release_mytm_mutex();
                }
                else
                    fdprintf("could not take mytm mutex - incoming packet dropped");
            }
        }
    }
    
    return 0;
}
开发者ID:Aleph-One-Marathon,项目名称:alephone,代码行数:35,代码来源:network_udp.cpp

示例10: receive_one_request

int			receive_one_request(t_trame *req,
					    t_connections *cnt)
{
  unsigned short	i;

  while (42)
    {
      if (SDLNet_CheckSockets(cnt->sset, (unsigned int)-1) < 0)
	{
	  fprintf(stderr, "SDLNet_CheckSockets: %s\n", SDLNet_GetError());
	  return (0);
	}
      for (i = 0; i < cnt->nb_clients; i++)
	{
	  if (recv_trame(cnt, &(cnt->clients[i]), req))
	    {
	      cnt->last_recv = &(cnt->clients[i]);
	      return (1);
	    }
	  if (cnt->clients[i].loss > NET_MAXLOSS)
	    return (0);
	}
    }
  // ne devrait pas en arriver jusque la:
  return (0);
}
开发者ID:BackupTheBerlios,项目名称:freewar-svn,代码行数:26,代码来源:receive_one_request.cpp

示例11: grabPacket

/** read a packet from the given TCPsocket
Returns -1 if some error occured, 0 if there was no data available and 1 if a
packet was successfully read.
Note: the socket has to be in the supplied socketset.
TODO: this function will bomb if a packet arrives in pieces, there is no
inherent guarantee that the next call will be made on the same socket. */
int
grabPacket(TCPsocket s, SDLNet_SocketSet ss, struct NetPacket* pkt)
{
	static char buf[NETPKTBUFSIZE];
	static int buf_count = 0;
	int rc;

	if (SDLNet_CheckSockets(ss, 0) <= 0)
		return 0;

	if(!SDLNet_SocketReady(s))
		return 0;

	rc = SDLNet_TCP_Recv(s, &buf[buf_count], NETPKTBUFSIZE - buf_count);
	if (rc <= 0) {
		/* closed connection? */
		return -1;
	} else if (rc != NETPKTBUFSIZE) {
		/* we got a partial packet. Store what we got in the static buffer and
		return so that the next call can read the rest. Hopefully. */
		buf_count = rc;
		return 0;
	} else {
		buf_count = 0;
		bufToPacket(buf, pkt);
		return 1;
	}
}
开发者ID:esohns,项目名称:jnb,代码行数:34,代码来源:net.c

示例12: SDLNet_AllocSocketSet

void NetworkCommandBuffer::Think()
{
	SDLNet_SocketSet set;

	set = SDLNet_AllocSocketSet ( 1 );
	if ( !set )
	{
		RaiseSocketError ( "SDLNet_AllocSocketSet" );
	}
	SocketSetEncapsulator free_on_quit ( set );
	if ( SDLNet_TCP_AddSocket ( set, socket ) < 0 )
		{
			RaiseSocketError ( "SDLNet_TCP_AddSocket" );
		}
	int numready = SDLNet_CheckSockets ( set, 0 );
	for ( ; numready == 1; numready = SDLNet_CheckSockets ( set, 0 ) )
		{
			char msg;
			int nbread = SDLNet_TCP_Recv ( socket, &msg, 1 );
			if ( nbread < 0 )
			{
				RaiseSocketError ( "SDLNet_TCP_Recv: " );
			}
			else if ( nbread == 0 )
			{
				std::cout << "SDLNet_TCP_Recv: Unexpected read of size 0\n";
				throw ReadSocketError();
			}
			if ( debug_all_message )
			{
				if ( msg < 32 )
					std::cout << "Read: 0x" << ( int ) msg << "\n";
				else
					std::cout << "Read: " << msg << "\n";
			}
			if (current_command_size > 0)
				AddCharToBuffer ( msg );
			else
				AddCharToCommandSize( msg );
		}
	if ( numready < 0 )
	{
		std::cout << "SDLNet_CheckSockets: " << SDLNet_GetError() << "\n";
		perror ( "SDLNet_CheckSockets" );
		throw ReadSocketError();
	}
}
开发者ID:Gamer2k4,项目名称:basinrogue,代码行数:47,代码来源:networkcommandbuffer.cpp

示例13: Connection_create

Connection* Connection_create(const char* ip, Uint16 port)
{
    Connection* self = (Connection*)calloc(1, sizeof(Connection));
    if(!self)
    {
        return NULL;
    }

    if(SDLNet_ResolveHost(&self->address, ip, port))
    {
        Connection_destroy(&self);
        return NULL;
    }

    if(!(self->socket = SDLNet_TCP_Open(&self->address)))
    {
        Connection_destroy(&self);
        return NULL;
    }

    if(!(self->socket_set = SDLNet_AllocSocketSet(1)))
    {
        Connection_destroy(&self);
        return NULL;
    }

    if(SDLNet_TCP_AddSocket(self->socket_set, self->socket) == -1)
    {
        Connection_destroy(&self);
        return NULL;
    }

    if(SDLNet_CheckSockets(self->socket_set, 5000) == 1)
    {
        Uint8 message = Connection_recv_flag(self);
        if(message == CONNECTED)
        {
            Uint8 buffer[6] = {0};
            Connection_recv_data(self, buffer, 6);

            self->local_address.host = SDLNet_Read32(buffer);
            self->local_address.port = SDLNet_Read16(buffer + 4);
            printf("Successfully connected to server\n");
            return self;
        }
        else if(message == FULL)
        {
            printf("Server is full\n");
        }
    }
    else
    {
        printf("Server is not responding\n");
    }

    Connection_destroy(&self);
    return NULL;
}
开发者ID:ErikWallstrom,项目名称:Client_Test,代码行数:58,代码来源:Connection.c

示例14: SDLNet_CheckSockets

void NetClient::update()
{
	SDLNet_CheckSockets(socketset, 0);

    if (SDLNet_SocketReady(tcpsock)) {
		handleserver();
	}

}
开发者ID:hu9o,项目名称:smw-next,代码行数:9,代码来源:net.cpp

示例15: SDLNet_CheckSockets

/**
 * @brief Comprobador "Ready"
 *
 * @return Si todo está listo y correcto para la conexión, devolverá true. En caso contrario, devolverá false.s
 *
 * Comprueba que todo esté correcto para la conexión.
 */
bool CTcpSocket::Ready() const {
    bool rd = false;
    int numready = SDLNet_CheckSockets(set, 0);
    if (numready == -1)
            std::cerr << "SDLNet_CheckSockets: " << SDLNet_GetError() << std:: endl;
      else
            if (numready)
                rd = SDLNet_SocketReady (m_Socket);
      return rd;
}
开发者ID:wikiti,项目名称:ullPong,代码行数:17,代码来源:CNet.cpp


注:本文中的SDLNet_CheckSockets函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。