Hello,

I want to add the support of sending http messages over UDP.
Please find attached the patch.
Please let me know if my patch is OK? and could you please merge it
to the mainline?

Could you please add my name and my email as Signed-off in the commit
message if you are going to merge my patch

MOHAMED Kallel
EasyCwmp open source maintainer
www.easycwmp.org



 include/curl/curl.h | 6 ++++++
 lib/connect.c       | 2 +-
 lib/http.c          | 1 +
 lib/transfer.c      | 2 +-
 lib/url.c           | 9 ++++++++-
 lib/urldata.h       | 3 +++
 6 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/include/curl/curl.h b/include/curl/curl.h
index 5b39a24..616a180 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1536,6 +1536,12 @@ typedef enum {
   /* set the SMTP auth originator */
   CINIT(MAIL_AUTH, OBJECTPOINT, 217),
 
+  /* Use UDP connection */
+   CINIT(UDP_CONNECT, LONG, 218),
+
+   /* Disable receive data from socket */
+    CINIT(DISABLE_RECEIVE, LONG, 219),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
diff --git a/lib/connect.c b/lib/connect.c
index 0afb1ee..5b38c52 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -928,7 +928,7 @@ singleipconnect(struct connectdata *conn,
     Curl_expire(data, conn->timeoutms_per_addr);
 
   /* Connect TCP sockets, bind UDP */
-  if(!isconnected && (conn->socktype == SOCK_STREAM)) {
+  if(!isconnected && ((conn->socktype == SOCK_STREAM) || data->set.force_udp)) 
{
     rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
     if(-1 == rc)
       error = SOCKERRNO;
diff --git a/lib/http.c b/lib/http.c
index daaafe3..8c6bdcf 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -1440,6 +1440,7 @@ CURLcode Curl_http_done(struct connectdata *conn,
   if(!premature && /* this check is pointless when DONE is called before the
                       entire operation is complete */
      !conn->bits.retry &&
+     !data->set.disable_receive &&
      ((http->readbytecount +
        data->req.headerbytecount -
        data->req.deductheadercount)) <= 0) {
diff --git a/lib/transfer.c b/lib/transfer.c
index 330b37a..4bd5428 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -398,7 +398,7 @@ static CURLcode readwrite_data(struct SessionHandle *data,
         bytestoread = (size_t)totalleft;
     }
 
-    if(bytestoread) {
+    if(bytestoread && !data->set.disable_receive) {
       /* receive data from the network! */
       result = Curl_read(conn, conn->sockfd, k->buf, bytestoread, &nread);
 
diff --git a/lib/url.c b/lib/url.c
index 918ce58..8d93a75 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2415,6 +2415,12 @@ CURLcode Curl_setopt(struct SessionHandle *data, 
CURLoption option,
   case CURLOPT_TCP_KEEPINTVL:
     data->set.tcp_keepintvl = va_arg(param, long);
     break;
+  case CURLOPT_UDP_CONNECT:
+    data->set.force_udp = TRUE;
+    break;
+  case CURLOPT_DISABLE_RECEIVE:
+    data->set.disable_receive = TRUE;
+    break;
 
   default:
     /* unknown tag and its companion, just ignore: */
@@ -3847,8 +3853,9 @@ static CURLcode setup_connection_internals(struct 
connectdata *conn)
 {
   const struct Curl_handler * p;
   CURLcode result;
+  struct SessionHandle *data = conn->data;
 
-  conn->socktype = SOCK_STREAM; /* most of them are TCP streams */
+  conn->socktype = data->set.force_udp ? SOCK_DGRAM : SOCK_STREAM; /* most of 
them are TCP streams unless if the user has forced it to be UDP */
 
   /* Scan protocol handler table. */
 
diff --git a/lib/urldata.h b/lib/urldata.h
index 7a275da..c430864 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1582,6 +1582,9 @@ struct UserDefined {
   long tcp_keepintvl;    /* seconds between TCP keepalive probes */
 
   size_t maxconnects;  /* Max idle connections in the connection cache */
+
+  bool force_udp; /* Force the connection to be UDP */
+  bool disable_receive; /* Disable the receive from the socket */
 };
 
 struct Names {

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to