GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Sep-2006, 06:14
tonmoy_C tonmoy_C is offline
New Member
 
Join Date: Sep 2006
Posts: 4
tonmoy_C is on a distinguished road

Is there any alternative function on select() [socket api] ?


hi,

In the socket related API, the select() function checks that
whether a socket is ready for reading / writing.

Is there any alternative function in socket API which can be used in place of
select().

thanks
Tonmoy
  #2  
Old 23-Sep-2006, 08:08
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,641
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Is there any alternative function on select() [socket api] ?


Quote:
Originally Posted by tonmoy_C
hi,

In the socket related API, the select() function checks that
whether a socket is ready for reading / writing.

Is there any alternative function in socket API which can be used in place of
select().

thanks
Tonmoy

1. What operating system and compiler?

2. What, exactly, do you need to do? (Specifically, what do you need that you can't do with select()?)

3. What sockets program reference material are you using?

Some implementations have pselect(); some have poll(). There are, undoubtedly, others. Not all poll() functions are exactly the same.


Regards,

Dave
  #3  
Old 23-Sep-2006, 08:33
tonmoy_C tonmoy_C is offline
New Member
 
Join Date: Sep 2006
Posts: 4
tonmoy_C is on a distinguished road

Re: Is there any alternative function on select() [socket api] ?


Hi Dave,

Thanks for your reply.

I am using Window's XP and Visual Studio 2003.

Actually, I have a client/Server program that brings some data from the server.
This program uses 'select()' call to manage various sockets. This program uses Winsock API.

But I need to port this program for Symbian OS (OS for mobile devices).
the Symbian S60 SDK does not support 'select()' function. But supports other function like:

ioctl(), getopt(), setopt()...

So, I need an alternative solution to support 'select()'.

Thanks
Tonmoy
  #4  
Old 23-Sep-2006, 08:43
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,641
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Is there any alternative function on select() [socket api] ?


Quote:
Originally Posted by tonmoy_C
This program uses 'select()' call to manage various sockets. This program uses Winsock API.

But I need to port this program for Symbian OS (OS for mobile devices).
the Symbian S60 SDK does not support 'select()' function.

Sorry; if the system doesn't have any traditional sockets programming functions (or POSIX functions), I can't really help. You could check to see if here is a support group or users forum for your target device. (Or, maybe --- if you are lucky--- someone else will see this thread and give a helpful response.)

Regards,

Dave
  #5  
Old 27-Sep-2006, 22:46
tonmoy_C tonmoy_C is offline
New Member
 
Join Date: Sep 2006
Posts: 4
tonmoy_C is on a distinguished road

Re: Is there any alternative function on select() [socket api] ?


well, If I would like to know that for which socket data is readable then How can I know it not using 'select()'?

Is it possible to know using other function in winsock api?

consider that I am using winsock api in windows.

Regards
Tonmoy
  #6  
Old 28-Sep-2006, 09:44
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,641
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Is there any alternative function on select() [socket api] ?


Quote:
Originally Posted by tonmoy_C
well, If I would like to know that for which socket data is readable then How can I know it not using 'select()'?

Is it possible to know using other function in winsock api?

consider that I am using winsock api in windows.

Regards
Tonmoy

What version of windows? What compiler?

With Borland bcc32 and Microsoft Visual C++ and Microsoft Visual C++ I have used select() the same way that I used it with Linux.


CPP / C++ / C Code:
int check_data(int socket_fd, int timeout_seconds)
{
    fd_set fdsr;
    struct timeval tv;

    int retval;
    FD_ZERO(&fdsr);
    FD_SET(socket_fd, &fdsr);

    tv.tv_sec = timeout_seconds;
    tv.tv_usec = 0;

    retval = select(socket_fd+1, &fdsr, NULL, NULL, &tv);
/*    printf("select returned %d\n", retval);*//*for debugging purposes */
    if (retval < 0) {
        perror("select"); /* big time problems */
    }
    return retval;
}

Since it returns the return value of select(), the calling program can know whether anything has come in over the socket connection. (return value of zero means no new bytes).

If this doesn't work for you:

Tell us what compiler you are using.
Show us the code.
If there are any compiler messages, paste them into your post.

Regards,

Dave
  #7  
Old 28-Sep-2006, 14:02
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,641
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Is there any alternative function on select() [socket api] ?


Quote:
Originally Posted by davekw7x
What version of windows? What compiler?

I am very sorry that I had a mental lapse and forgot that you had already told us that you were using a different compiler that didn't support select(). I apologize for the wasted bandwidth.

Some implementations support a "nonblocking" socket, and certain options can be uset with a function called "setsockoptions() after the socket has been opened. You could check in your sockets.h file (or wherever it is that your sockets functions prototypes are located) and see if it has the setsockoptions() function, and further look to see if there is some kind of macro defintion for SO_RCVTIMEO. If it's there, then you may be able use this to set a timeout value to keep read() from blocking.

I don't have Symbian, so I can't help you. Is there any documentation about Symbian sockets stuff that came with your compiler, or is available from wherever you got your compiler.

Oops,

Dave
  #8  
Old 28-Sep-2006, 22:20
tonmoy_C tonmoy_C is offline
New Member
 
Join Date: Sep 2006
Posts: 4
tonmoy_C is on a distinguished road

Re: Is there any alternative function on select() [socket api] ?


Thanks Dave.....

Please forget about symbian.

Actually, In my last post I mean that:

"If I use winsock api then can I achive the almost same facility of select() from other api?"

Although winsock supports 'select()', but I do not want to use it.

My intention is to know what select() does and then try to implement its functionality.

For example, select() takes an array of readble socket. and checks if any data is available on that readable sockets. Am I right?

If I am right, then I want to do same thing using other socket api.

As you said that there is setsockopt().
Using setsockopt() I can set a socket as non-blocking. This is first step.
After making a socket non-blocking, now I want to check whether a data is avalibale on that socket or not.

Here is my sample logic idea:

1. All the readable sockets are already set as non-blocking

2.
int My_Select(int readDesc[]) // Analogous of select()
{
for(i=0 ;i < MAX_SOCKET_NUM; i++)
{
// trying to implement....Here I need other alternative api support
// if possible....(this is my actual subject of query)

if (isDataAvailable(desc[i]))
add this desc[i] to another readable sockets array

}
}

This is my idea.
Please make your comments.

Regards
Tonmoy
  #9  
Old 28-Sep-2006, 23:36
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,641
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Is there any alternative function on select() [socket api] ?


Quote:
Originally Posted by tonmoy_C

Using setsockopt() I can set a socket as non-blocking. This is first step.
After making a socket non-blocking, now I want to check whether a data is avalibale on that socket or not.

I don't know exactly why you want to do something like select() but don't want to use select().

However if you really want to see if you can do it, you could try to read one byte from a socket (read() or recv() or whatever). If no bytes are ready, sInce it's non-blocking, the read function will return with a value of zero (after whatever timeout period you set).

Of course if the socket has actually received a byte (or more), then the read function will get that byte from the socket, store that byte in your buffer, and return with a value of one.

Now if you just want to check to see if a byte is ready to be read, but don't want to read it yet, you can keep track of the byte in the buffer (so that your next read function starts at the next position), or maybe store it in a special variable somewhere else if you need the buffer for other purposes in the meantime. Then when you really want to read some bytes, get that one first, then read the other bytes from the socket (if any).

Kind of like the way the standard library function ungetc() works: The ungetc() function can't actually push the char back onto an input stream; it just puts it into some static storage area where getc() looks first whenever you want to read a char.

Seems kind of awkward, and maybe I didn't explain it very well, but as I said, I really don't see the point, since select() can test the state of a socket (or a set of sockets) without actually reading it.
Regards,

Dave
  #10  
Old 13-May-2008, 02:02
manila.goel manila.goel is offline
New Member
 
Join Date: May 2008
Posts: 1
manila.goel is an unknown quantity at this point

can select() be used to chk file descriptor??


i wrking in vxworks5.4, i hv opened a serial device file for serial communication and using
select(serialDataPtr->fileDesc+1,readFdSet, NULL, NULL, &tv);
to chk if any data to be read from the file descriptor.
Is this valid??
can we used select for this if not any alternative for this..
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
[Tutorial] Function Pointers aaroncohn CPP / C++ Forum 4 17-Feb-2006 11:33
C++ PhoneBook marita CPP / C++ Forum 46 12-Jun-2005 12:10
[GIM] gim.h dsmith C Programming Language 0 18-Jan-2005 08:48
Revising Script style ?????? pepee MySQL / PHP Forum 4 14-Apr-2004 04:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:12.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.