cURL / Mailing Lists / curl-library / Single Mail

curl-library

Setting IP ToS and socket priority.

From: Ben Greear <greearb_at_candelatech.com>
Date: Wed, 02 Mar 2005 12:18:46 -0800

Hello!

I'd like to add the ability to set a particular IP ToS on sockets as
soon as they are opened. I would also like to the socket priority.

I did not see any options or call backs that could accomplish this,
though maybe I missed something...

I think the most flexible would be a callback that was called whenever
a new socket was created (before it connected, even).

Maybe something like:

int curl_socket_open_handler(int sk);

int curl_easy_setopt(curl, CURLOPT_SOCKET_OPEN_CALLBACK, &curl_socket_open_handler));

I could muck with socket options to my hearts content in the curl_socket_open_handler
method.

Alternately, you could allow setting ToS and Priority values in the
curl handle and deal with the ioctl calls internally. The code to
actually set ToS and priority looks something like:

/* Returns actual priority that was set, or < 0 on error */
int setPriorityHelper(int sk, int val) {
    VLOG_WRN(VLOG << "Setting SKB-Priority, sk: " << sk << " val: " << val << endl);
    if (setsockopt(sk, SOL_SOCKET, SO_PRIORITY, (char*)&val, sizeof(val)) < 0) {
       VLOG_ERR(VLOG << "ERROR: tcp-start, setsockopt PRIORITY: "
                << strerror(errno) << endl);
       return -errno;
    }//if

    int new_val = 0;
    socklen_t slt = sizeof(new_val);
    if (getsockopt(sk, SOL_SOCKET, SO_PRIORITY, (char*)(&new_val), &slt) < 0) {
       VLOG_ERR(VLOG << "ERROR: tcp-start, getsockopt PRIORITY: "
                << strerror(errno) << endl);
       return -errno;
    }//if
    else {
       if (val != new_val) {
          VLOG_WRN(VLOG << "Didn't set PRIORITY as desired, requested: "
                   << val << " current is: " << new_val << endl);
       }
    }
    return new_val;
}//setPriorityHelper

And, for TOS:
       int val = tos;
       if (setsockopt(dev_socket, SOL_IP, IP_TOS, (char*)&val, sizeof(tos)) < 0) {
          VLOG_ERR(VLOG << "ERROR: tcp-start, setsockopt TOS: " << strerror(errno) << endl);
          return -1;
       }//if

Thanks,
Ben

-- 
Ben Greear <greearb_at_candelatech.com>
Candela Technologies Inc  http://www.candelatech.com
Received on 2005-03-02