db_sockets.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * db_socket.c
  15. *
  16. * This file contains operands for streams with URIs that start with
  17. * "tcp:", "tcp.srv:", "udp:", "udp.srv:".
  18. */
  19. #include "pal_defs.h"
  20. #include "pal.h"
  21. #include "pal_internal.h"
  22. #include "pal_debug.h"
  23. #include "pal_error.h"
  24. #include "api.h"
  25. /* 96 bytes is the minimal size of buffer to store a IPv4/IPv6
  26. address */
  27. #define PAL_SOCKADDR_SIZE 96
  28. /* listen on a tcp socket */
  29. static int tcp_listen (PAL_HANDLE * handle, char * uri, int create)
  30. {
  31. return -PAL_ERROR_NOTIMPLEMENTED;
  32. }
  33. /* accept a tcp connection */
  34. static int tcp_accept (PAL_HANDLE handle, PAL_HANDLE *client)
  35. {
  36. return -PAL_ERROR_NOTIMPLEMENTED;
  37. }
  38. /* connect on a tcp socket */
  39. static int tcp_connect (PAL_HANDLE * handle, char * uri, int create)
  40. {
  41. return -PAL_ERROR_NOTIMPLEMENTED;
  42. }
  43. /* 'open' operation of tcp stream */
  44. static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri,
  45. int access, int share, int create, int options)
  46. {
  47. size_t uri_len = strlen(uri) + 1;
  48. if (uri_len > PAL_SOCKADDR_SIZE)
  49. return -PAL_ERROR_TOOLONG;
  50. char uri_buf[PAL_SOCKADDR_SIZE];
  51. memcpy(uri_buf, uri, uri_len);
  52. if (!strcmp_static(type, "tcp.srv"))
  53. return tcp_listen(handle, uri_buf, create);
  54. if (!strcmp_static(type, "tcp"))
  55. return tcp_connect(handle, uri_buf, create);
  56. return -PAL_ERROR_NOTSUPPORT;
  57. }
  58. /* 'read' operation of tcp stream */
  59. static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, size_t len, void * buf)
  60. {
  61. return -PAL_ERROR_NOTIMPLEMENTED;
  62. }
  63. /* write' operation of tcp stream */
  64. static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, size_t len, const void * buf)
  65. {
  66. return -PAL_ERROR_NOTIMPLEMENTED;
  67. }
  68. /* used by 'open' operation of tcp stream for bound socket */
  69. static int udp_bind (PAL_HANDLE *handle, char * uri, int create)
  70. {
  71. return -PAL_ERROR_NOTIMPLEMENTED;
  72. }
  73. /* used by 'open' operation of tcp stream for connected socket */
  74. static int udp_connect (PAL_HANDLE * handle, char * uri)
  75. {
  76. return -PAL_ERROR_NOTIMPLEMENTED;
  77. }
  78. static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri,
  79. int access, int share, int create, int options)
  80. {
  81. char buf[PAL_SOCKADDR_SIZE];
  82. size_t len = strlen(uri);
  83. if (len >= PAL_SOCKADDR_SIZE)
  84. return -PAL_ERROR_TOOLONG;
  85. memcpy(buf, uri, len + 1);
  86. if (strcmp_static(type, "udp.srv"))
  87. return udp_bind(hdl, buf, create);
  88. if (strcmp_static(type, "udp"))
  89. return udp_connect(hdl, buf);
  90. return -PAL_ERROR_NOTSUPPORT;
  91. }
  92. static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, size_t len, void * buf)
  93. {
  94. return -PAL_ERROR_NOTIMPLEMENTED;
  95. }
  96. static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, size_t len,
  97. void * buf, char * addr, size_t addrlen)
  98. {
  99. return -PAL_ERROR_NOTIMPLEMENTED;
  100. }
  101. static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, size_t len, const void * buf)
  102. {
  103. return -PAL_ERROR_NOTIMPLEMENTED;
  104. }
  105. static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, size_t len,
  106. const void * buf, const char * addr, size_t addrlen)
  107. {
  108. return -PAL_ERROR_NOTIMPLEMENTED;
  109. }
  110. static int socket_delete (PAL_HANDLE handle, int access)
  111. {
  112. return -PAL_ERROR_NOTIMPLEMENTED;
  113. }
  114. static int socket_close (PAL_HANDLE handle)
  115. {
  116. return -PAL_ERROR_NOTIMPLEMENTED;
  117. }
  118. static int socket_attrquerybyhdl (PAL_HANDLE handle, PAL_STREAM_ATTR * attr)
  119. {
  120. return -PAL_ERROR_NOTIMPLEMENTED;
  121. }
  122. static int socket_getname (PAL_HANDLE handle, char * buffer, size_t count)
  123. {
  124. return -PAL_ERROR_NOTIMPLEMENTED;
  125. }
  126. struct handle_ops tcp_ops = {
  127. .getname = &socket_getname,
  128. .open = &tcp_open,
  129. .waitforclient = &tcp_accept,
  130. .read = &tcp_read,
  131. .write = &tcp_write,
  132. .delete = &socket_delete,
  133. .close = &socket_close,
  134. .attrquerybyhdl = &socket_attrquerybyhdl,
  135. };
  136. struct handle_ops udp_ops = {
  137. .getname = &socket_getname,
  138. .open = &udp_open,
  139. .read = &udp_receive,
  140. .write = &udp_send,
  141. .delete = &socket_delete,
  142. .close = &socket_close,
  143. .attrquerybyhdl = &socket_attrquerybyhdl,
  144. };
  145. struct handle_ops udpsrv_ops = {
  146. .getname = &socket_getname,
  147. .open = &udp_open,
  148. .readbyaddr = &udp_receivebyaddr,
  149. .writebyaddr = &udp_sendbyaddr,
  150. .delete = &socket_delete,
  151. .close = &socket_close,
  152. .attrquerybyhdl = &socket_attrquerybyhdl,
  153. };
  154. PAL_HANDLE _DkBroadcastStreamOpen (void)
  155. {
  156. return NULL;
  157. }
  158. static int64_t mcast_send (PAL_HANDLE handle, uint64_t offset, uint64_t size,
  159. const void * buf)
  160. {
  161. return -PAL_ERROR_NOTIMPLEMENTED;
  162. }
  163. static int64_t mcast_receive (PAL_HANDLE handle, uint64_t offset, uint64_t size, void * buf)
  164. {
  165. return -PAL_ERROR_NOTIMPLEMENTED;
  166. }
  167. static int mcast_close (PAL_HANDLE handle)
  168. {
  169. return -PAL_ERROR_NOTIMPLEMENTED;
  170. }
  171. struct handle_ops mcast_ops = {
  172. .write = &mcast_send,
  173. .read = &mcast_receive,
  174. .close = &mcast_close,
  175. };