cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: LIBCURL couldn't start connections for some of EASY handle

From: yifei.chen <yifei.chen_at_keygate-inc.com>
Date: Fri, 25 Apr 2008 10:49:52 +0800

Daniel£¬ thanks for your help!

 

I changed my code as below and test again, the problem is still there: A
lot of EASY handles have been added into MULIT handle, but LIBCURL didn¡¯t
start connections for some of them.

 

 

typedef struct sock_info

{

       int action; /*CURL_POLL_IN CURL_POLL_OUT */

       struct epoll_event ev;

       int evset;

       

} sock_info_t;

 

 

static void remSock(sock_info_t *pSockInfo, curl_socket_t fd,
netio_context_t *pNetIOContext)

{

       if(pSockInfo) {

              if(pSockInfo->evset) {

                     if(-1 == epoll_ctl(pNetIOContext->epfd, EPOLL_CTL_DEL,
fd, NULL))

                            g_warning("*********faled in epoll_ctl() 1,
errno %d, fd %d*************\n", errno, fd);

                     pNetIOContext->total_sockets--;

              }

              free(pSockInfo);

       }

}

 

static void setSock(sock_info_t *pSockInfo, curl_socket_t fd, CURL *handle,
int action, netio_context_t *pNetIOContext)

{

       pSockInfo->action = action;

       if(pSockInfo->evset) {

 

              if(action & CURL_POLL_IN)

                     pSockInfo->ev.events = EPOLLIN;

              if(action & CURL_POLL_OUT)

                     pSockInfo->ev.events |= EPOLLOUT;

 

              if(-1 == epoll_ctl(pNetIOContext->epfd, EPOLL_CTL_MOD, fd,
&(pSockInfo->ev)))

                     g_warning("*********faled in epoll_ctl() 3, errno %d,
fd %d*************\n", errno, fd);

              

       } else {

              pSockInfo->ev.data.fd = fd;

 

              if(action & CURL_POLL_IN)

                     pSockInfo->ev.events = EPOLLIN;

              if(action & CURL_POLL_OUT)

                     pSockInfo->ev.events |= EPOLLOUT;

                     

              if(-1 == epoll_ctl(pNetIOContext->epfd, EPOLL_CTL_ADD, fd,
&(pSockInfo->ev)))

                     g_warning("*********faled in epoll_ctl() 2, errno %d,
fd %d*************\n", errno, fd);

              else

                     pNetIOContext->total_sockets++;

 

              pSockInfo->evset = 1;

       }

       

       

}

 

static void addSock(curl_socket_t fd, CURL *handle, int action,
netio_context_t *pNetIOContext)

{

       sock_info_t *pSockInfo = (sock_info_t*)malloc(sizeof(sock_info_t));

       bzero(pSockInfo, sizeof(sock_info_t));

 

       setSock(pSockInfo, fd, handle, action, pNetIOContext);

       curl_multi_assign(pNetIOContext->pMultiHandlers, fd, pSockInfo);

       

}

 

static int mySocketFunc(CURL *handle, curl_socket_t fd, int action, void
*cbp, void *sockp)

{

 

       netio_context_t *pNetIOContext = (netio_context_t*)cbp;

 

       sock_info_t *pSockInfo = (sock_info_t*)sockp;

 

 

       if (action == CURL_POLL_REMOVE) {

 

              remSock(pSockInfo, fd, pNetIOContext);

 

       } else {

 

              if(pSockInfo == NULL) {

 

                     g_debug("*******Adding action %d***********\n",
action);

                     addSock(fd, handle, action, pNetIOContext);

              } else {

                     g_debug("*******Change action from %d to
%d***********\n", pSockInfo->action, action);

                     setSock(pSockInfo, fd, handle, action, pNetIOContext);

              }

       }

       return 0;

}

 

From: Daniel Stenberg <daniel_at_haxx.se
<mailto:daniel_at_haxx.se?Subject=Re:%20LIBCURL%20couldn't%20start%20connect
ions%20for%20some%20of%20EASY%20handle> >
Date: Thu, 24 Apr 2008 14:35:58 +0200 (CEST)

On Thu, 24 Apr 2008, yifei.chen wrote:

> I use LIBCURL ( 7.18.0 ) in my project recently. // socket callback

> static int mySocketFunc(CURL *e, curl_socket_t s, int what, void *cbp,
void
> *sockp)
> {
> netio_context_t *pNetIOContext = (netio_context_t*)cbp;
> struct epoll_event ev;
> memset(&ev, 0, sizeof(struct epoll_event));
> if (what == CURL_POLL_REMOVE) {
> epoll_ctl(pNetIOContext->epfd, EPOLL_CTL_DEL, s, &ev);
> } else {
> ev.data.fd = s;
> ev.events = EPOLLIN | EPOLLPRI;

I don't follow the logic here. Why would you want those events only no
matter
what libcurl specicies in the 'what' argument?

> curl_easy_setopt(pHandle, CURLOPT_FORBID_REUSE, 1);
> curl_easy_setopt(pHandle, CURLOPT_FRESH_CONNECT, 1);

Really?

 
Received on 2008-04-25