PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/http-server-close-immediately.c

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C | 60 lines | 33 code | 9 blank | 18 comment | 6 complexity | a87745d9871a58ea119fc470db53fb7c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. http-server-close-immediately.c - HTTP server that closes connection immediately
  3. Copyright (C) 2008 siliconforks.com
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include <config.h>
  17. #include <assert.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include "http-server.h"
  21. int main(void) {
  22. #ifdef __MINGW32__
  23. WSADATA data;
  24. if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {
  25. return 1;
  26. }
  27. #endif
  28. SOCKET s = socket(PF_INET, SOCK_STREAM, 0);
  29. assert(s != INVALID_SOCKET);
  30. int optval = 1;
  31. setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &optval, sizeof(optval));
  32. struct sockaddr_in a;
  33. a.sin_family = AF_INET;
  34. a.sin_port = htons(8000);
  35. a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  36. int result = bind(s, (struct sockaddr *) &a, sizeof(a));
  37. assert(result == 0);
  38. result = listen(s, 5);
  39. assert(result == 0);
  40. for (;;) {
  41. struct sockaddr_in client_address;
  42. size_t size = sizeof(client_address);
  43. int client_socket = accept(s, (struct sockaddr *) &client_address, &size);
  44. assert(client_socket > 0);
  45. closesocket(client_socket);
  46. }
  47. return 0;
  48. }