Overview
Comment: | Added more log messages and support for error pages |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
70ecb45a61751dbf49c4a03fd7f0909e |
User & Date: | rkeene on 2014-02-04 11:51:37 |
Other Links: | manifest | tags |
Context
2014-02-04
| ||
12:02 | Check sendfile() output and log check-in: 16b1aecd99 user: rkeene tags: trunk | |
11:51 | Added more log messages and support for error pages check-in: 70ecb45a61 user: rkeene tags: trunk | |
10:18 | Added basic support for HTTP requests check-in: 4bbee8f607 user: rkeene tags: trunk | |
Changes
Modified filed.c from [0f86783dca] to [456b09599d].
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 | 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 | + + + + + + + + + + + + | #include <sys/sendfile.h> #include <sys/socket.h> #include <sys/types.h> #include <arpa/inet.h> #include <sys/mman.h> #include <sys/stat.h> #include <pthread.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <stdio.h> #include <time.h> /* Default values */ #define MAX_FAILURE_COUNT 30 #define PORT 8080 #define THREAD_COUNT 10 #define BIND_ADDR "::" /* Arguments for worker threads */ struct filed_worker_thread_args { int fd; }; /* File information */ struct filed_fileinfo { int fd; size_t len; char *lastmod; char lastmod_b[64]; char *type; }; /* Initialize process */ static void filed_init(void) { mlockall(MCL_CURRENT | MCL_FUTURE); } /* Listen on a particular address/port */ static int filed_listen(const char *address, unsigned int port) { struct sockaddr_in6 addr; int pton_ret, bind_ret, listen_ret; int fd; addr.sin6_family = AF_INET6; addr.sin6_flowinfo = 0; |
︙ | |||
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + + - + - + + + - - - + + + + + + + - + - - + + + + + + + + + + + + + + + + + + - + - - + + + + + + - + + + + - + + + + + + + + + - + + + + + + | return(-1); } return(fd); } /* Initialize logging thread */ static int filed_logging_thread_init(void) { /* XXX:TODO: Unimplemented */ return(0); } /* Log a message */ |
︙ | |||
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | + + + + + + + + | fd = accept(master_fd, (struct sockaddr *) &addr, &addrlen); /* * If we fail, make a note of it so we don't go into a loop of * accept() failing */ if (fd < 0) { /* Log the new connection */ filed_log_msg("ACCEPT_FAILED"); failure_count++; continue; } /* Log the new connection */ filed_log_msg("NEW_CONNECTION SRC_ADDR=... SRC_PORT=... FD=..."); /* Reset failure count*/ failure_count = 0; /* Handle socket */ filed_handle_client(fd); } /* XXX:TODO: Report error */ return(NULL); } /* Create worker threads */ static int filed_worker_threads_init(int fd, int thread_count) { struct filed_worker_thread_args *arg; pthread_t threadid; int pthread_ret; int i; for (i = 0; i < thread_count; i++) { arg = malloc(sizeof(*arg)); arg->fd = fd; pthread_ret = pthread_create(&threadid, NULL, filed_worker_thread, arg); if (pthread_ret != 0) { return(-1); } } return(0); } /* Run process */ int main(int argc, char **argv) { int port = PORT, thread_count = THREAD_COUNT; const char *bind_addr = BIND_ADDR; int fd; /* Ignore */ argc = argc; |
︙ |