Solved

How to use setsockopt under unix /solaris 2.6

Posted on 2004-08-18
9
1,615 Views
Last Modified: 2013-12-05
I am trying to add a timeout to send and recv functions for TCPSocket  in C++ on unix/solaris 2.6 environment .
to solve I  am trying to use setsockopt with SO_RCVTIMEO for recv and I am getting the compilation errors as
code:
        struct timeval tv;
        tv.tv_sec =  timeout_n ;
        tv.tv_usec = 0 ;
        setsockopt( sockDesc , SOL_SOCKET , SO_RCVTIMEO , &tv , sizeof(tv) ) ;
        setsockopt( sockDesc , SOL_SOCKET , SO_SNDTIMEO , &tv , sizeof(tv) ) ;
Error:
Formal argument 4 of type const char* in call to setsockopt(int, int, int, const char*, int) is being passed timeval*.

Please advise.

0
Comment
Question by:bmanik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
9 Comments
 
LVL 6

Accepted Solution

by:
bkthompson2112 earned 500 total points
ID: 11834781
Hi bmanik,

Using Tru64, this works:
setsockopt( sockDesc , SOL_SOCKET , SO_RCVTIMEO , (void *) &tv , sizeof(tv) ) ;   // ---------added (void *)

What's the man page say?

bkt
0
 

Author Comment

by:bmanik
ID: 11835141
man page doesnt specify SO_RCVTIMEO ,but I was following richard stevens book and coded accordingly , there must be some other way to set the time outs , pls advise .
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11835156
> Formal argument 4

would be &tv.

Make sure you've cast it to the correct type.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bmanik
ID: 11835268
Thanks , I did type cast it and its now clean compiled , going ahead for testing it now .
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11835347
You're welcome.  Hope it's working now.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11838729
check the man page .... this particular option, though existing is not necessarily working on all platforms.

It wont report an error but will be silently ignored
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11914580
>I did type cast it and its now clean compiled , going ahead for testing it now

bmanik, how did the testing go?  is it working now?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Introduction to Processes

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question