IBM developerWorks
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old September 9th, 2002, 07:37 AM
OB_redemption's Avatar
OB_redemption OB_redemption is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 32 OB_redemption User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
is this the right way to setsockopt()?

i'm trying to use setsockopt() to turn off Nagle's algorithm, to set the send buffer to zero, and to set the receive timeout to 30 seconds... is the code i'm using below correct? and where should i place this code - after a socket() or after the connect()?

Code:
    int tcpnodelay_flag = 1;
    size_t sendbuffer_sz = 0;
    struct timeval timeout;

    /* set TCP_NODELAY to turn off Nagle's algorithm */
    if(setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *) &tcpnodelay_flag, sizeof(int)) == -1)
    {
        perror("setsockopt (TCP_NODELAY)");
        exit(1);
    }
    /* set send buffer 0 */
    if(setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char *) &sendbuffer_sz, sizeof(size_t)) == -1)
    {
        perror("setsockopt (SO_SNDBUF)");
        exit(1);
    }
    /* set receive timeout to 30s */
    timeout.tv_sec = 30;
    timeout.tv_usec = 0;
    if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1)
    {
        perror("setsockopt (SO_RCVTIMEO)");
        exit(1);
    }

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > is this the right way to setsockopt()?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway