select error 0x80410005 - help(RaF, J.F., TyRaNiD, pspZorba)

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

select error 0x80410005 - help(RaF, J.F., TyRaNiD, pspZorba)

Post by Rex_VF5 »

First of all: sorry for asking for attention this way but I am desperate and do not know how to proceed at all. The code obviously works on many platforms (it's libupnp) but on PSP give this strange error that strerrorr can't describe.

Here's the snippet from the code (it gives the error on the line ret = select(FD_SETSIZE , &rdSet, NULL, NULL, NULL );):

Code: Select all

/************************************************************************
 * Function: RunMiniServer
 *
 * Parameters:
 *	MiniServerSockArray *miniSock - Socket Array
 *
 * Description:
 * 	Function runs the miniserver. The MiniServer accepts a 
 *	new request and schedules a thread to handle the new request.
 *	Checks for socket state and invokes appropriate read and shutdown 
 *	actions for the Miniserver and SSDP sockets 
 *
 * Return: void
 ************************************************************************/
static void
RunMiniServer( MiniServerSockArray *miniSock )
{
    char errorBuffer[ERROR_BUFFER_LEN];
    struct sockaddr_in clientAddr;
    socklen_t clientLen;
    SOCKET connectHnd;
    SOCKET miniServSock = miniSock->miniServerSock;
    SOCKET miniServStopSock =  miniSock->miniServerStopSock;
    SOCKET ssdpSock = miniSock->ssdpSock;
#ifdef INCLUDE_CLIENT_APIS
    SOCKET ssdpReqSock = miniSock->ssdpReqSock;
#endif

    fd_set expSet;
    fd_set rdSet;
    unsigned int maxMiniSock;
    int byteReceived;
    char requestBuf[256];
    int ret = 0;

    maxMiniSock = max( miniServSock, miniServStopSock) ;
    maxMiniSock = max( maxMiniSock, (SOCKET)(ssdpSock) );
#ifdef INCLUDE_CLIENT_APIS
    maxMiniSock = max( maxMiniSock, (SOCKET)(ssdpReqSock) );
#endif
    ++maxMiniSock;

    gMServState = MSERV_RUNNING;
    while( TRUE ) {
        FD_ZERO( &rdSet );
        FD_ZERO( &expSet );

        FD_SET( miniServStopSock, &expSet );
        FD_SET( miniServSock, &rdSet );
        FD_SET( miniServStopSock, &rdSet );
        FD_SET( ssdpSock, &rdSet );
#ifdef INCLUDE_CLIENT_APIS
        FD_SET( ssdpReqSock, &rdSet );
#endif

        ret = select(FD_SETSIZE , &rdSet, NULL, NULL, NULL );
//        ret = select( maxMiniSock, &rdSet, NULL, &expSet, NULL );
        if ( ret == -1 ) {
            strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
            UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
                "Error %X in select(): %s\n", errno, errorBuffer );
//                "Error in select(): %s\n", errorBuffer );
	    /* Avoid 100% CPU in case of repeated error in select() */
	    isleep( 1 );
            continue;
        } else {
            if( FD_ISSET( miniServSock, &rdSet ) ) {
                clientLen = sizeof( struct sockaddr_in );
                connectHnd = accept( miniServSock,
                    ( struct sockaddr * )&clientAddr, &clientLen );
                if( connectHnd == -1 ) {
                    strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
                    UpnpPrintf( UPNP_INFO, MSERV, __FILE__, __LINE__,
                        "miniserver: Error in accept(): %s\n", errorBuffer );
                    continue;
                }
                schedule_request_job( connectHnd, &clientAddr );
            }
As you can see I have attempted to use FD_SETSIZE instead of socket number because I have read in some thread that can cause some issues. Didn't help. The debug message was supposed to give a textual reason of what went wrong through strerror_r but gives nothing (I ahev also tried strerror with the same result).

Any idea what this means? I couldn't find anything similar anywhere...
Last edited by Rex_VF5 on Sat Dec 06, 2008 10:18 pm, edited 4 times in total.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Have you tried just printing the error number? Maybe it's something strerror doesn't recognize.
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

Post by Rex_VF5 »

J.F. wrote:Have you tried just printing the error number? Maybe it's something strerror doesn't recognize.
The error number is contained in the subject of this thread: 80410005 printed through %X.
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

Post by Rex_VF5 »

Please, anyone?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Your first arg is wrong. It needs to be max_socket_num+1.
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

Post by Rex_VF5 »

J.F. wrote:Your first arg is wrong. It needs to be max_socket_num+1.
As can be seen in the sources I changed it from ret = select( maxMiniSock, &rdSet, NULL, &expSet, NULL ); because I found somewhere such suggestion. With the original line it produces the same error.
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

Post by Rex_VF5 »

I have changed the select line back to original and ran this through debugger and that gave interesting results:

Upon executing select the errno equals to 0 which in turn translates to "Connection timed out" in errorBuffer. When doing next step (i.e. UpnpPrintf( UPNP_CRITICAL, SSDP, __FILE__, __LINE__, "Error in select(): %s\n", errno, errorBuffer ); the debugger hangs and on the PSP only first few letters of the message appear. When running thins directly it prints the "Error in select(): " but nothing after it and seems to continue.

To me it seems like some memory corruption issue or something like that. However this is code used on many platforms (Linux, BSD, Win32, ...) so I guess there's hardly something wrong with that. It's gotta be something PSP specific... Any ideas???
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Might be too small a stack or heap. When doing 3.xx+ homebrew in prx form, you need to set the heap size specifically. Also, the stack defaults to 256K. If you use more local storage than that, you'll need to set the stack size as well.
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

Post by Rex_VF5 »

J.F. wrote:Might be too small a stack or heap. When doing 3.xx+ homebrew in prx form, you need to set the heap size specifically. Also, the stack defaults to 256K. If you use more local storage than that, you'll need to set the stack size as well.
Is there a way in gdb (or ddd) to find out current stack/heap utilization? Also how do you change the default stack size?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Only way to find rough stack utilisation is to use the thinfo command in psplink on the thread or in your own code call sceKernelGetThreadStackFreeSize(0) and print the result. As for changing the stack size add a PSP_MAIN_THREAD_STACK_SIZE_KB(x) line where x is the stack size in KB.
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

Post by Rex_VF5 »

I've increased heap size to 4096K and stack size to 1024K and the result is the same. It hangs in debugger with only printing the begging of the debug line. When ran directly it continues past this point somehow...

Would someone be willing to have a look at the .prx/.elf if I posted it?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Looking at the finished product is worthless, it's the code that matters. If you don't want to post code (beyond what you already have), then you'll just have to work it out yourself. Sometimes, it's not the function that is crashing that is causing the crash. Maybe somewhere else you walk on the stack, or use a variable incorrectly, corrupting other structures or code. We've seen programs posted here by people looking for help where the problem was one char array in a completely different part of the app was one character too short. If you don't see a problem with the code under question, don't focus on it to the exclusion of all else.
User avatar
Rex_VF5
Posts: 44
Joined: Wed Dec 26, 2007 6:24 am

Post by Rex_VF5 »

J.F.,

no problem with posting the whole sources - after all it is just 3 libraries put together (libupnp, pthreads-emb and mcupnp) and one slightly modified example from mcupnp. When I wrote I'll post .elf/.prx I just thought the sources were stored inside .elf.

Here's the file: http://www.sendspace.com/file/i6fof7 It contains 3 directories:
  • pthreads-emb - pthreads implementation (in the trunk directory) - see http://forums.ps2dev.org/viewtopic.php?p=76418. This is needed for the following 2 libraries. As noted there, you need to copy pthread.h and sched.h to SDK include directory manually.
    libupnp-1.6.6 - Portable UPnP library from http://pupnp.sourceforge.net/ I just modified it a bit to be able to compile and also added configure-psp.sh. Then just make clean;make;make install If you wanted to reconfigure, be sure to --disable-samples as the are meant for Linux. Also --enable-debug enables debugging output. There is a sample test application in upnp/test that just attempts to initialize the whole stuff and print the configured options.
    mcupnp - contains libmcupnp from http://users.telenet.be/bruno.keymolen/libmcupnp.html - Free C++ UPnP(v1) MediaServer Client API. make clean;make;make install There is a upnpcmd subdirectory there that contains sample application I am trying to make work on PS (I modified it a bit to be able to control it by PSP). make clean; make there and try to run.
All the Makefile(s) were changed to turn off optimizations and also to include debugging symbols. The problematic behavior with select occurs in RunMiniServer function residing in libupnp-1.6.6/upnp/src/genlib/miniserver/miniserver.c

Thanks for your helping.
Post Reply