net.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. typedef enum { net_type_int = 0x03, net_type_float = 0x0B,
  10. net_type_char = 0x30, net_type_str = 0xB0,
  11. net_type_none = 0x33 } net_type_t;
  12. typedef void (net_error_hdlr_t)(net_type_t get, net_type_t wanted, void *data);
  13. /* Error handlers */
  14. void net_set_error_handler(net_error_hdlr_t *hdlr, void *data);
  15. net_error_hdlr_t net_error_abort;
  16. net_error_hdlr_t net_error_ignore;
  17. const char *net_type_name(net_type_t t);
  18. /* Opening sockets */
  19. int net_connect_to(const char *host, int port, char *err, int errsz,
  20. struct timeval *to);
  21. int net_listen_at(int port, int max_con, char *err, int errsz);
  22. /* Writing data */
  23. void net_wr_string(FILE *file, const char *s);
  24. void net_wr_int(FILE *file, int val);
  25. void net_wr_flag(FILE *file, gboolean val);
  26. void net_wr_char(FILE *file, char c);
  27. void net_wr_float(FILE *file, float f);
  28. /* Reading data */
  29. char *net_get_string(int fd);
  30. int net_get_int(int fd);
  31. gboolean net_get_flag(int fd);
  32. char net_get_char(int fd);
  33. float net_get_float(int fd);
  34. /* Checking values */
  35. gboolean net_chk_string(int fd, const char *s);
  36. gboolean net_chk_int(int fd, int val);
  37. gboolean net_chk_flag(int fd, gboolean val);
  38. gboolean net_chk_char(int fd, char c);
  39. gboolean net_chk_float(int fd, float f);
  40. int net_chk_str_list(int fd, ...); /* -1 = not in list */
  41. /* Ack */
  42. gboolean net_wait_ack(int fd);
  43. void net_send_ack(FILE *file);
  44. void net_send_abort(FILE *file);
  45. #endif