io_socket.c 917 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
  3. * All rights reserved
  4. *
  5. * "THE BEER-WARE LICENSE" (Revision 42):
  6. * Sergey Lyubka wrote this file. As long as you retain this notice you
  7. * can do whatever you want with this stuff. If we meet some day, and you think
  8. * this stuff is worth it, you can buy me a beer in return.
  9. */
  10. #include "defs.h"
  11. static int
  12. read_socket(struct stream *stream, void *buf, size_t len)
  13. {
  14. assert(stream->chan.sock != -1);
  15. return (recv(stream->chan.sock, buf, len, 0));
  16. }
  17. static int
  18. write_socket(struct stream *stream, const void *buf, size_t len)
  19. {
  20. assert(stream->chan.sock != -1);
  21. return (send(stream->chan.sock, buf, len, 0));
  22. }
  23. static void
  24. close_socket(struct stream *stream)
  25. {
  26. assert(stream->chan.sock != -1);
  27. (void) closesocket(stream->chan.sock);
  28. }
  29. const struct io_class _shttpd_io_socket = {
  30. "socket",
  31. read_socket,
  32. write_socket,
  33. close_socket
  34. };