Sha256: 57425469ddbd51f9606ef107f475e6acead6e4451fb715f538ff546abddcff24

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

#ifndef EV_HTTP_H
#define EV_HTTP_H

#include "config.h"
#include "ev_dispatch.h"
#include <curl/curl.h>

namespace EVD {

  struct HttpClient {
    HttpClient( Dispatch *disp );
    ~HttpClient();

    // created to manage the socket transitions
    struct SocketInfo {
      SocketInfo( HttpClient *client, curl_socket_t sock, CURL *e, int action );
      virtual ~SocketInfo();

      static void response_cb(struct ev_loop *loop, struct ev_io *w, int revents);
      void set_sock( curl_socket_t sock, CURL *e, int action );
      void finish();

      int m_action;
      long m_timeout;
      struct ev_io *m_watcher;
      CURL *m_handle;
      HttpClient *m_client;
      Dispatch *m_dispatch;
    };

    void check_handles();

    static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp);
    static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp);
    static void timeout_cb(struct ev_loop *loop, struct ev_timer *w, int revents);

    int m_active; // number of active requests
    CURLM *m_handle;
    Dispatch *m_disp;
    bool m_timer_set;
    struct ev_timer m_timer;
  };

  // follow the curl handle for the duration of it's request
  struct HttpRequest : public Request {
    HttpRequest( Dispatch &dispatch, const std::string &url );
    virtual ~HttpRequest();

    virtual bool enable();

    void finish( CURLcode rc );

    virtual void set_key( request_t key ){ Request::set_key(key); this->response->id = key; }

    static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data);
    static int prog_cb(void *p, double dltotal, double dlnow, double ult, double uln);

    Response *response;

    CURL *m_handle;
    HttpClient *m_client;
    char error[CURL_ERROR_SIZE];
  };

}

#endif

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evdispatch-0.1.4 ext/revdispatch/libdispatch-0.1/src/ev_http.h