×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Sep 2003
    Location
    Ukraine
    Posts
    75

    Where is analog of select function

    Where is analog of select function ?

    select
    The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O.

    int select(
    int nfds,
    fd_set FAR *readfds,
    fd_set FAR *writefds,
    fd_set FAR *exceptfds,
    const struct timeval FAR *timeout
    );

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    24

    Re: Where is analog of select function

    i am also facing same problem so can any one say where in select system call is.
    In which header file it is or instead of select any other function in symbian

  3. #3
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Where is analog of select function

    There isn't an equivalent for select calls in Symbian. You can achieve similar functionality for single sockets using ioctl() function in the stdlib implementation, or use KIOctlSelect if using RSockets. This should only be used in certain circumstances (ie. porting code) otherwise, you should review your design. Check the forum, as this topic has been already discussed thoroughly.

  4. #4
    Regular Contributor
    Join Date
    Jul 2006
    Posts
    60

    Re: Where is analog of select function

    Hi,

    Check the forum, as this topic has been already discussed thoroughly.
    There is little bit discussion about ioctl() not on 'KIOctlSelect' like how to use it. No concrete example found in the forum.

    The purpose of ioctl() is found in some discussion in the forum.

    But it could be better if somebody helps on it by giving complete example.


    Tonmoy

  5. #5
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Where is analog of select function

    Code:
            iSelectFlags() = flags;  // TPckgBuf<TUint32> iSelectFlags;
    
            iSocket.Ioctl(KIOctlSelect, iStatus, &iSelectFlags, KSOLSocket);
            SetActive();
    Then on RunL(), iSelectFlags contains the bitset, depending on the socket status.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    31

    Re: Where is analog of select function

    I am porting some sockets C code and need an implementation of select - this is what I have so far (not proven yet - i'd like comments on this).

    Code:
    #include <sys/time.h>
    #include <sys/ioctl.h>
    #include <sys/types.h>
    #include <estlib.h> // must be after sys/ioctl.h due to ioctl() redefinition
    
    int select(int nfds, fd_set *read, fd_set *write, fd_set *except, struct timeval *tv)
    {
    	RTimer Timer;
    	TRequestStatus TimerStatus = KRequestPending;
    	TRequestStatus FdStatus[32];
    	int fd, set = 0;
    	fd_set read_out, write_out;
    
    	FD_ZERO(&read_out);
    	FD_ZERO(&write_out);
    	
    	Timer.CreateLocal();
    	Timer.After(TimerStatus, tv->tv_sec * 1000000 + tv->tv_usec);
    
    wait_again:
    	for(fd = 0; fd <= nfds; fd++) {
    		unsigned int flags = 0;
    		if (FD_ISSET(fd, read))
    			flags |= E32SELECT_READ;
    		if (FD_ISSET(fd, write))
    			flags |= E32SELECT_WRITE;
    		if (flags)
    			ioctl(fd, E32IOSELECT, &flags, FdStatus[fd]);
    	}
    	
    	User::WaitForAnyRequest();
    	
    	for(fd = 0; fd <= nfds; fd++) {
    		unsigned int flags;
    		if (FD_ISSET(fd, read) || FD_ISSET(fd, write)) {
    			ioctl_complete(fd, E32IOSELECT, (void *) &flags, FdStatus[fd]);
    			if (flags & E32SELECT_READ) {
    				set++;
    				FD_SET(fd, &read_out);
    			}
    			if (flags & E32SELECT_WRITE) {
    				set++;
    				FD_SET(fd, &write_out);
    			}
    		}
    	}
    	
    	if (set == 0 && TimerStatus == KRequestPending)
    		goto wait_again;
    	
    	Timer.Close();
    	
    	memcpy(read, &read_out, sizeof(read_out));
    	memcpy(write, &write_out, sizeof(write_out));
    	
    	return set;
    }
    I don't see why Symbian doesn't have something like this in the stdlib for those applications that need it. (And yes - I'm running this on a separate thread without any active objects).

  7. #7
    Regular Contributor
    Join Date
    Sep 2006
    Location
    Australia, NSW
    Posts
    200

    Re: Where is analog of select function

    There is a synchronous version, but it is hidden in es_sock.h global variables. Took me a month to figure it out. Documentation on STDLIB doesn't even mention it! It just says "Select is not possible. Period".
    Code:
    TPckgBuf<TInt> sel;
    sock.GetOpt(KSOSelectPoll, KSOLSocket, sel);
    
    if (sel() & KSockSelectRead)
    {
    	// Pending data to read
    }
    if (sel() & KSockSelectWrite)
    {
    	// Ready to write
    }
    if (sel() & KSockSelectExcept)
    {
    	// Error
    }
    I did a porting of POSIX networking application that heavily relied on "select", and it was a royal pain in the neck.
    Last edited by sysctl; 2007-01-20 at 18:35.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    31

    Re: Where is analog of select function

    Interesting - good find!!!

    It looks like it supports selecting on a single socket only. I need something that works with fd's, so I don't have to port these.

    Simon

  9. #9
    Regular Contributor
    Join Date
    Sep 2006
    Location
    Australia, NSW
    Posts
    200

    Re: Where is analog of select function

    Yes, one socket only. I had to write helper functions and typedefs (FD_ISSET, fd_set, etc) based on this snippet and it worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×