Connect Timeout
Connect Timeout
*next post*
Last edited by steffven on Tue Nov 25, 2008 7:51 am, edited 1 time in total.
The same problem with this code:
I really don't understand why it doesn't work...
Code: Select all
pcip = ...
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
socketaddr.sin_family = AF_INET;
socketaddr.sin_addr.s_addr = inet_addr(pcip);
socketaddr.sin_port = htons(12345);
struct timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
fail = connect(sock,(struct sockaddr*)&socketaddr,sizeof(socketaddr));
if (fail<0)
{
sceKernelExitGame();
}
Code: Select all
pcip = ...
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
socketaddr.sin_family = AF_INET;
socketaddr.sin_addr.s_addr = inet_addr(pcip);
socketaddr.sin_port = htons(12345);
struct timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); // Returns 0
fail = connect(sock,(struct sockaddr*)&socketaddr,sizeof(socketaddr));
if (fail<0)
{
sceKernelExitGame();
}
Code: Select all
struct timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); // Returns 0
Take a look at existing code. For example, in PSPRadio/PSP/SharedLib/PSPApp/httpget.cpp, they use:
so it looks like your argument to setsockopt needs to be a u32 and microseconds instead of struct timeval.
Code: Select all
u32 timeo;
timeo = 3 *1000*1000; /** timeout is in microseconds */
Log(LOG_LOWLEVEL, "http_connect(): Calling Setsockopt()");
if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)) < 0)
Hmm, tested it but neither of this 2 work:
I still have to wait around 1minute, frustrating...
Code: Select all
int connectWithTimeout (int sfd,
struct sockaddr *addr,
int addrlen,
u32 *timeo)
{
struct timeval sv;
socklen_t svlen = sizeof sv;
int ret;
if (!timeo)
return connect (sfd, addr, addrlen);
if (getsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&sv, &svlen) < 0)
return -1;
if (setsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char *)timeo, sizeof *timeo) < 0)
return -1;
ret = connect (sfd, addr, addrlen);
setsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&sv, sizeof sv);
return ret;
}
void ...
{
char *pcip;
int fail;
struct sockaddr_in socketaddr;
pcip = ...
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
socketaddr.sin_family = AF_INET;
socketaddr.sin_addr.s_addr = inet_addr(pcip);
socketaddr.sin_port = htons(12345);
u32 timeo;
timeo = 3 *1000*1000;
fail = connectWithTimeout(sock,(struct sockaddr*)&socketaddr,sizeof(socketaddr),&timeo);
if (fail<0)
{
sceKernelExitGame();
}
Code: Select all
void ...
{
char *pcip;
int fail;
struct sockaddr_in socketaddr;
pcip = ...
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
socketaddr.sin_family = AF_INET;
socketaddr.sin_addr.s_addr = inet_addr(pcip);
socketaddr.sin_port = htons(12345);
u32 timeo;
timeo = 3 *1000*1000;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)); // Still returns 0
fail = connect(sock,(struct sockaddr*)&socketaddr,sizeof(socketaddr));
if (fail<0)
{
sceKernelExitGame();
}
There's other code in PSPradio that does something different, sets the socket nonblocking then polls connect() for a result. Maybe try that. Or just find some application that behaves as you desire, and see if they figured it out. Or, reverse engineer the firmware further and find out how to do it the Sony way.