ry / ebb fork watch download tarball
public
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Ryan Dahl (author)
Tue Feb 26 17:41:31 -0800 2008
commit  a791fbb16843b516dbb8e50aa9e4e007c391c927
tree    21e9aba300b3e4eae2482293d8c625b472c35840
parent  e371bdae561942f088985098dece7eed08e28e85
ebb / src / ebb.h
100644 103 lines (81 sloc) 2.407 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Ebb Web Server
 * Copyright (c) 2007 Ry Dahl <ry.d4hl@gmail.com>
 * This software is released under the "MIT License". See README file for details.
 */
#ifndef ebb_h
#define ebb_h
 
#include <sys/socket.h>
#include <netinet/in.h>
#include <glib.h>
 
#define EV_STANDALONE 1
#include "ev.h"
 
#include "parser.h"
 
 
typedef struct ebb_server ebb_server;
typedef struct ebb_client ebb_client;
 
#define EBB_BUFFERSIZE (40*1024)
#define EBB_MAX_CLIENTS 950
#define EBB_TIMEOUT 30.0
#define EBB_MAX_ENV 100
#define EBB_TCP_COMMON \
  unsigned open : 1; \
  int fd; \
  struct sockaddr_in sockaddr;
 
/*** Ebb Client ***/
void ebb_client_close(ebb_client*);
int ebb_client_read(ebb_client *client, char *buffer, int length);
void ebb_client_write(ebb_client*, const char *data, int length);
void ebb_client_finished( ebb_client *client);
 
enum { EBB_REQUEST_METHOD
     , EBB_REQUEST_URI
     , EBB_FRAGMENT
     , EBB_REQUEST_PATH
     , EBB_QUERY_STRING
     , EBB_HTTP_VERSION
     , EBB_SERVER_NAME
     , EBB_SERVER_PORT
     , EBB_CONTENT_LENGTH
     };
 
struct ebb_client {
  EBB_TCP_COMMON
  
  ebb_server *server;
  http_parser parser;
  
  char request_buffer[EBB_BUFFERSIZE];
  ev_io read_watcher;
  size_t read, nread_from_body;
  
  char upload_file_filename[200];
  FILE *upload_file;
  
  int content_length;
  
  ev_io write_watcher;
  GString *response_buffer;
  size_t written;
  
  ev_timer timeout_watcher;
  
  /* the ENV structure */
  int env_size;
  const char *env_fields[EBB_MAX_ENV];
  int env_field_lengths[EBB_MAX_ENV];
  const char *env_values[EBB_MAX_ENV];
  int env_value_lengths[EBB_MAX_ENV];
};
 
/*** Ebb Server ***/
 
typedef void (*ebb_request_cb)(ebb_client*, void*);
 
ebb_server* ebb_server_alloc();
void ebb_server_free(ebb_server*);
void ebb_server_init( ebb_server *server
                    , struct ev_loop *loop
                    , ebb_request_cb request_cb
                    , void *request_cb_data
                    );
int ebb_server_listen_on_port(ebb_server*, const int port);
int ebb_server_listen_on_socket(ebb_server*, const char *socketpath);
void ebb_server_unlisten(ebb_server*);
 
struct ebb_server {
  EBB_TCP_COMMON
  char *port;
  char *socketpath;
  ev_io request_watcher;
  ebb_client clients[EBB_MAX_CLIENTS];
  struct ev_loop *loop;
  void *request_cb_data;
  ebb_request_cb request_cb;
};
 
#endif ebb_h