network.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "platform.h"
  18. namespace embree
  19. {
  20. namespace network
  21. {
  22. /*! type for a socket */
  23. typedef struct opaque_socket_t* socket_t;
  24. /*! exception thrown when other side disconnects */
  25. struct Disconnect : public std::exception {
  26. virtual const char* what() const throw() {
  27. return "network disconnect";
  28. }
  29. };
  30. /*! creates a socket bound to a port */
  31. socket_t bind(unsigned short port);
  32. /*! listens for an incoming connection and accepts that connection */
  33. socket_t listen(socket_t sockfd);
  34. /*! initiates a connection */
  35. socket_t connect(const char* host, unsigned short port);
  36. /*! read data from the socket */
  37. void read(socket_t socket, void* data, size_t bytes);
  38. /*! write data to the socket */
  39. void write(socket_t socket, const void* data, size_t bytes);
  40. /*! flushes the write buffer */
  41. void flush(socket_t socket);
  42. /*! close a socket */
  43. void close(socket_t socket);
  44. /*! reads a bool from the socket */
  45. bool read_bool(socket_t socket);
  46. /*! reads a character from the socket */
  47. char read_char(socket_t socket);
  48. /*! reads an integer from the socket */
  49. int read_int(socket_t socket);
  50. /*! reads a float from the socket */
  51. float read_float(socket_t socket);
  52. /*! reads a string from the socket */
  53. std::string read_string(socket_t socket);
  54. /*! writes a bool to the socket */
  55. void write(socket_t socket, bool value);
  56. /*! writes a character to the socket */
  57. void write(socket_t socket, char value);
  58. /*! writes an integer to the socket */
  59. void write(socket_t socket, int value);
  60. /*! writes a float to the socket */
  61. void write(socket_t socket, float value);
  62. /*! writes a string to the socket */
  63. void write(socket_t socket, const std::string& str);
  64. }
  65. }