db_sockets.c 5.9 KB

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