I have simple code:
#define NUM_UA_SOCK 100
typedef struct _UA_REQUEST
{
string full_url;
uint32_t url_adler32 ;
TCPsocket sock_ua ;
uint32_t status_flag ; // ref Enum STATUS
} UA_REQUEST ;
UA_REQUEST GLB_ARRAY__UA_REQ[ NUM_UA_SOCK ] ;
void handle_ua_sock_ready( uint32_t ii )
{
string _req_mstr;
byte*request = (byte*) _req_mstr.c_str() ;
byte*pcrlf = NULL ;
UA_REQUEST*ar = GLB_ARRAY__UA_REQ ;
// Get request from UA
int32_t nrcv ;
printf("index = %lu\n", ii);
TCPsocket sock = ar[ii].sock_ua;
nrcv = SDLNet_TCP_Recv( sock , request , MAXLEN ) ;
printf("After index = %lu\n", ii);
}
The ii variable in begin of handle_ua_sock_ready() func has the 0 value. After invoking nrcv = SDLNet_TCP_Recv( sock , request , MAXLEN ) ; line it becomes to have something very big value for instance 1852397344. It is single-threaded app. I'm using VS 2010, SDL, SDL_net libraries. PS: When I compiled it under Linux, it works fine.
You're passing in
request
to theSDLNet_TCP_Recv
function and telling that function thatrequest
points to a buffer of sizeMAXLEN
. Asrequest
comes from casting away the constness from the buffer of an emptystd::string
this is clearly wrong.You want a vector