asio_link.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // $Id$
  15. #ifndef __ASIO_LINK_H
  16. #define __ASIO_LINK_H 1
  17. #include <string.h>
  18. #include <dns/message.h>
  19. class AuthSrv;
  20. namespace asio_link {
  21. struct IOServiceImpl;
  22. ///\brief stands for one query client including its network information and query message
  23. class UserInfo
  24. {
  25. public:
  26. enum {QUERY_PACKAGE_MAX_LEN = 0xffff};
  27. enum QueryProtocol{ QueryThroughTCP , QueryThroughUDP};
  28. UserInfo(QueryProtocol protocol):queryProtocol_(protocol), message_(isc::dns::Message::PARSE), needs_reply_(false), is_message_valid_(false) {}
  29. void setIOInfo(const std::string &ipaddr, unsigned short port, int socketfd){
  30. ipaddr_ = ipaddr;
  31. port_ = port;
  32. socket_ = socketfd;
  33. }
  34. const std::string & getIPAddress()const { return ipaddr_;}
  35. UserInfo::QueryProtocol getProtocolType()const { return queryProtocol_;}
  36. unsigned short getPort()const { return port_;}
  37. int getSocket()const { return socket_; }
  38. void setQueryRawData(const char *data, size_t dataLen);
  39. bool needsReply() const { return needs_reply_;} //if even head part isn't complete then no need send reply back
  40. bool isMessageValid() const { return is_message_valid_;}
  41. isc::dns::Message & getMessage() { return message_;}
  42. const isc::dns::Message & getMessage() const{ return message_;}
  43. private:
  44. std::string ipaddr_;
  45. unsigned short port_;
  46. int socket_;
  47. QueryProtocol queryProtocol_;
  48. isc::dns::Message message_;
  49. bool needs_reply_;
  50. bool is_message_valid_;
  51. };
  52. class IOService {
  53. public:
  54. IOService(AuthSrv* auth_server, const char* port,
  55. const bool use_ipv4, const bool use_ipv6);
  56. ~IOService();
  57. void run();
  58. void stop();
  59. asio::io_service& get_io_service();
  60. private:
  61. IOServiceImpl* impl_;
  62. };
  63. } // asio_link
  64. #endif // __ASIO_LINK_H
  65. // Local Variables:
  66. // mode: c++
  67. // End: