PageRenderTime 22ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/http-client-close-after-request.c

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C | 57 lines | 28 code | 10 blank | 19 comment | 5 complexity | 83c5b69715aa4b86205346de0f8cda29 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. http-client-close-after-request.c - HTTP client that closes connection after sending request
  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. int result;
  29. struct sockaddr_in a;
  30. a.sin_family = AF_INET;
  31. a.sin_port = htons(8000);
  32. a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  33. SOCKET s = socket(PF_INET, SOCK_STREAM, 0);
  34. assert(s != INVALID_SOCKET);
  35. result = connect(s, (struct sockaddr *) &a, sizeof(a));
  36. assert(result == 0);
  37. /* send request */
  38. char * message = "GET http://127.0.0.1:8000/ HTTP/1.1\r\nConnection: close\r\nHost: 127.0.0.1:8000\r\n\r\n";
  39. size_t message_length = strlen(message);
  40. ssize_t bytes_sent = send(s, message, message_length, 0);
  41. assert(bytes_sent == (ssize_t) message_length);
  42. closesocket(s);
  43. return 0;
  44. }