pulsarnet.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* $Id: net.h,v 1.8 2001/04/28 15:29:25 kilobug Exp $ */
  2. #ifndef __PROLO_NET_LIB_H__
  3. #define __PROLO_NET_LIB_H__
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <sys/time.h>
  7. #include "../general.h"
  8. #include <glib.h>
  9. #define PROTOCOL_VERSION 0x4207
  10. typedef enum { net_type_int = 0x03, net_type_float = 0x0B,
  11. net_type_char = 0x30, net_type_str = 0xB0,
  12. net_type_none = 0x33 } net_type_t;
  13. typedef void (net_error_hdlr_t)(net_type_t get, net_type_t wanted, void *data);
  14. /* Error handlers */
  15. void net_set_error_handler(net_error_hdlr_t *hdlr, void *data);
  16. net_error_hdlr_t net_error_abort;
  17. net_error_hdlr_t net_error_ignore;
  18. const char *net_type_name(net_type_t t);
  19. /* Opening sockets */
  20. int net_connect_to(const char *host, int port, char *err, int errsz,
  21. struct timeval *to);
  22. int net_listen_at(int port, int max_con, char *err, int errsz);
  23. /* Writing data */
  24. void net_wr_string(FILE *file, const char *s);
  25. void net_wr_int(FILE *file, int val);
  26. void net_wr_flag(FILE *file, gboolean val);
  27. void net_wr_char(FILE *file, char c);
  28. void net_wr_float(FILE *file, float f);
  29. /* Reading data */
  30. char *net_get_string(int fd);
  31. int net_get_int(int fd);
  32. gboolean net_get_flag(int fd);
  33. char net_get_char(int fd);
  34. float net_get_float(int fd);
  35. /* Checking values */
  36. gboolean net_chk_string(int fd, const char *s);
  37. gboolean net_chk_int(int fd, int val);
  38. gboolean net_chk_flag(int fd, gboolean val);
  39. gboolean net_chk_char(int fd, char c);
  40. gboolean net_chk_float(int fd, float f);
  41. int net_chk_str_list(int fd, ...); /* -1 = not in list */
  42. /* Ack */
  43. gboolean net_wait_ack(int fd);
  44. void net_send_ack(FILE *file);
  45. void net_send_abort(FILE *file);
  46. #endif