PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
happyhttp Namespace Reference

Classes

class  Connection
 
class  Response
 
class  Wobbly
 

Typedefs

typedef void(* ResponseBegin_CB) (const Response *r, void *userdata)
 
typedef void(* ResponseData_CB) (const Response *r, void *userdata, const unsigned char *data, int numbytes)
 
typedef void(* ResponseComplete_CB) (const Response *r, void *userdata)
 

Enumerations

enum  {
  CONTINUE = 100 , SWITCHING_PROTOCOLS = 101 , PROCESSING = 102 , OK = 200 ,
  CREATED = 201 , ACCEPTED = 202 , NON_AUTHORITATIVE_INFORMATION = 203 , NO_CONTENT = 204 ,
  RESET_CONTENT = 205 , PARTIAL_CONTENT = 206 , MULTI_STATUS = 207 , IM_USED = 226 ,
  MULTIPLE_CHOICES = 300 , MOVED_PERMANENTLY = 301 , FOUND = 302 , SEE_OTHER = 303 ,
  NOT_MODIFIED = 304 , USE_PROXY = 305 , TEMPORARY_REDIRECT = 307 , BAD_REQUEST = 400 ,
  UNAUTHORIZED = 401 , PAYMENT_REQUIRED = 402 , FORBIDDEN = 403 , NOT_FOUND = 404 ,
  METHOD_NOT_ALLOWED = 405 , NOT_ACCEPTABLE = 406 , PROXY_AUTHENTICATION_REQUIRED = 407 , REQUEST_TIMEOUT = 408 ,
  CONFLICT = 409 , GONE = 410 , LENGTH_REQUIRED = 411 , PRECONDITION_FAILED = 412 ,
  REQUEST_ENTITY_TOO_LARGE = 413 , REQUEST_URI_TOO_LONG = 414 , UNSUPPORTED_MEDIA_TYPE = 415 , REQUESTED_RANGE_NOT_SATISFIABLE = 416 ,
  EXPECTATION_FAILED = 417 , UNPROCESSABLE_ENTITY = 422 , LOCKED = 423 , FAILED_DEPENDENCY = 424 ,
  UPGRADE_REQUIRED = 426 , INTERNAL_SERVER_ERROR = 500 , NOT_IMPLEMENTED = 501 , BAD_GATEWAY = 502 ,
  SERVICE_UNAVAILABLE = 503 , GATEWAY_TIMEOUT = 504 , HTTP_VERSION_NOT_SUPPORTED = 505 , INSUFFICIENT_STORAGE = 507 ,
  NOT_EXTENDED = 510
}
 

Functions

void BailOnSocketError (const char *context)
 
bool datawaiting (int sock)
 
struct in_addr * atoaddr (const char *address)
 

Typedef Documentation

◆ ResponseBegin_CB

typedef void(* happyhttp::ResponseBegin_CB) (const Response *r, void *userdata)

Definition at line 54 of file happyhttp.h.

◆ ResponseComplete_CB

typedef void(* happyhttp::ResponseComplete_CB) (const Response *r, void *userdata)

Definition at line 56 of file happyhttp.h.

◆ ResponseData_CB

typedef void(* happyhttp::ResponseData_CB) (const Response *r, void *userdata, const unsigned char *data, int numbytes)

Definition at line 55 of file happyhttp.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CONTINUE 
SWITCHING_PROTOCOLS 
PROCESSING 
OK 
CREATED 
ACCEPTED 
NON_AUTHORITATIVE_INFORMATION 
NO_CONTENT 
RESET_CONTENT 
PARTIAL_CONTENT 
MULTI_STATUS 
IM_USED 
MULTIPLE_CHOICES 
MOVED_PERMANENTLY 
FOUND 
SEE_OTHER 
NOT_MODIFIED 
USE_PROXY 
TEMPORARY_REDIRECT 
BAD_REQUEST 
UNAUTHORIZED 
PAYMENT_REQUIRED 
FORBIDDEN 
NOT_FOUND 
METHOD_NOT_ALLOWED 
NOT_ACCEPTABLE 
PROXY_AUTHENTICATION_REQUIRED 
REQUEST_TIMEOUT 
CONFLICT 
GONE 
LENGTH_REQUIRED 
PRECONDITION_FAILED 
REQUEST_ENTITY_TOO_LARGE 
REQUEST_URI_TOO_LONG 
UNSUPPORTED_MEDIA_TYPE 
REQUESTED_RANGE_NOT_SATISFIABLE 
EXPECTATION_FAILED 
UNPROCESSABLE_ENTITY 
LOCKED 
FAILED_DEPENDENCY 
UPGRADE_REQUIRED 
INTERNAL_SERVER_ERROR 
NOT_IMPLEMENTED 
BAD_GATEWAY 
SERVICE_UNAVAILABLE 
GATEWAY_TIMEOUT 
HTTP_VERSION_NOT_SUPPORTED 
INSUFFICIENT_STORAGE 
NOT_EXTENDED 

Definition at line 60 of file happyhttp.h.

60 {
61 // 1xx informational
62 CONTINUE = 100,
64 PROCESSING = 102,
65
66 // 2xx successful
67 OK = 200,
68 CREATED = 201,
69 ACCEPTED = 202,
71 NO_CONTENT = 204,
72 RESET_CONTENT = 205,
73 PARTIAL_CONTENT = 206,
74 MULTI_STATUS = 207,
75 IM_USED = 226,
76
77 // 3xx redirection
78 MULTIPLE_CHOICES = 300,
80 FOUND = 302,
81 SEE_OTHER = 303,
82 NOT_MODIFIED = 304,
83 USE_PROXY = 305,
85
86 // 4xx client error
87 BAD_REQUEST = 400,
88 UNAUTHORIZED = 401,
89 PAYMENT_REQUIRED = 402,
90 FORBIDDEN = 403,
91 NOT_FOUND = 404,
93 NOT_ACCEPTABLE = 406,
95 REQUEST_TIMEOUT = 408,
96 CONFLICT = 409,
97 GONE = 410,
98 LENGTH_REQUIRED = 411,
104 EXPECTATION_FAILED = 417,
106 LOCKED = 423,
107 FAILED_DEPENDENCY = 424,
108 UPGRADE_REQUIRED = 426,
109
110 // 5xx server error
112 NOT_IMPLEMENTED = 501,
113 BAD_GATEWAY = 502,
115 GATEWAY_TIMEOUT = 504,
118 NOT_EXTENDED = 510,
119};
@ METHOD_NOT_ALLOWED
Definition happyhttp.h:92
@ TEMPORARY_REDIRECT
Definition happyhttp.h:84
@ MULTI_STATUS
Definition happyhttp.h:74
@ PAYMENT_REQUIRED
Definition happyhttp.h:89
@ PROXY_AUTHENTICATION_REQUIRED
Definition happyhttp.h:94
@ NOT_ACCEPTABLE
Definition happyhttp.h:93
@ NON_AUTHORITATIVE_INFORMATION
Definition happyhttp.h:70
@ INSUFFICIENT_STORAGE
Definition happyhttp.h:117
@ BAD_REQUEST
Definition happyhttp.h:87
@ MOVED_PERMANENTLY
Definition happyhttp.h:79
@ NOT_MODIFIED
Definition happyhttp.h:82
@ UPGRADE_REQUIRED
Definition happyhttp.h:108
@ HTTP_VERSION_NOT_SUPPORTED
Definition happyhttp.h:116
@ SWITCHING_PROTOCOLS
Definition happyhttp.h:63
@ REQUEST_ENTITY_TOO_LARGE
Definition happyhttp.h:100
@ INTERNAL_SERVER_ERROR
Definition happyhttp.h:111
@ UNAUTHORIZED
Definition happyhttp.h:88
@ UNSUPPORTED_MEDIA_TYPE
Definition happyhttp.h:102
@ EXPECTATION_FAILED
Definition happyhttp.h:104
@ RESET_CONTENT
Definition happyhttp.h:72
@ REQUEST_URI_TOO_LONG
Definition happyhttp.h:101
@ PRECONDITION_FAILED
Definition happyhttp.h:99
@ MULTIPLE_CHOICES
Definition happyhttp.h:78
@ LENGTH_REQUIRED
Definition happyhttp.h:98
@ NOT_IMPLEMENTED
Definition happyhttp.h:112
@ UNPROCESSABLE_ENTITY
Definition happyhttp.h:105
@ SERVICE_UNAVAILABLE
Definition happyhttp.h:114
@ PARTIAL_CONTENT
Definition happyhttp.h:73
@ GATEWAY_TIMEOUT
Definition happyhttp.h:115
@ FAILED_DEPENDENCY
Definition happyhttp.h:107
@ REQUEST_TIMEOUT
Definition happyhttp.h:95
@ REQUESTED_RANGE_NOT_SATISFIABLE
Definition happyhttp.h:103

Function Documentation

◆ atoaddr()

struct in_addr * happyhttp::atoaddr ( const char *  address)

Definition at line 177 of file happyhttp.cpp.

178{
179 struct hostent *host;
180 static struct in_addr saddr;
181
182 // First try nnn.nnn.nnn.nnn form
183 saddr.s_addr = inet_addr(address);
184 if (saddr.s_addr != -1)
185 return &saddr;
186
187 host = gethostbyname(address);
188 if( host )
189 return (struct in_addr *) *host->h_addr_list;
190
191 return 0;
192}

Referenced by happyhttp::Connection::connect().

◆ BailOnSocketError()

void happyhttp::BailOnSocketError ( const char *  context)

Definition at line 76 of file happyhttp.cpp.

77{
78#ifdef WIN32
79
80 int e = WSAGetLastError();
81 const char* msg = GetWinsockErrorString( e );
82#else
83 const char* msg = strerror( errno );
84#endif
85 throw Wobbly( "%s: %s", context, msg );
86}

Referenced by happyhttp::Connection::connect(), datawaiting(), happyhttp::Connection::pump(), and happyhttp::Connection::send().

◆ datawaiting()

bool happyhttp::datawaiting ( int  sock)

Definition at line 154 of file happyhttp.cpp.

155{
156 fd_set fds;
157 FD_ZERO( &fds );
158 FD_SET( sock, &fds );
159
160 struct timeval tv;
161 tv.tv_sec = 0;
162 tv.tv_usec = 0;
163
164 int r = select( sock+1, &fds, NULL, NULL, &tv);
165 if (r < 0)
166 BailOnSocketError( "select" );
167
168 if( FD_ISSET( sock, &fds ) )
169 return true;
170 else
171 return false;
172}
#define NULL
Definition BinReloc.cpp:317
void BailOnSocketError(const char *context)
Definition happyhttp.cpp:76

References BailOnSocketError(), and NULL.

Referenced by happyhttp::Connection::pump().