system_transport-test.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* libanode: the Anode C reference implementation
  2. * Copyright (C) 2009-2010 Adam Ierymenko <[email protected]>
  3. *
  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 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <sys/socket.h>
  20. #include "../anode.h"
  21. #include "../impl/thread.h"
  22. static int do_client()
  23. {
  24. AnodeTransport *st;
  25. AnodeSocket *udp_sock;
  26. int run = 1;
  27. st = AnodeSystemTransport_new(NULL);
  28. if (!st) {
  29. printf("FAILED: unable to construct AnodeSystemTransport.\n");
  30. return -1;
  31. }
  32. printf("Created AnodeSystemTransport.\n");
  33. while (run)
  34. st->poll(st);
  35. }
  36. static int do_server()
  37. {
  38. AnodeTransport *st;
  39. AnodeSocket *udp_sock;
  40. AnodeSocket *tcp_sock;
  41. int run = 1;
  42. st = AnodeSystemTransport_new(NULL);
  43. if (!st) {
  44. printf("FAILED: unable to construct AnodeSystemTransport.\n");
  45. return -1;
  46. }
  47. printf("Created AnodeSystemTransport.\n");
  48. while (run)
  49. st->poll(st);
  50. }
  51. int main(int argc,char **argv)
  52. {
  53. if (argc == 2) {
  54. if (!strcmp(argv[1],"client"))
  55. return do_client();
  56. else if (!strcmp(argv[1],"server"))
  57. return do_server();
  58. }
  59. printf("Usage: system_transport-test <client / server>\n");
  60. return -1;
  61. }