io_endpoint.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2011 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. #include <config.h>
  15. #include <unistd.h> // for some IPC/network system calls
  16. #include <sys/socket.h>
  17. #include <netinet/in.h>
  18. #include <asio.hpp>
  19. #include <asiolink/io_address.h>
  20. #include <asiolink/io_error.h>
  21. #include <asiolink/tcp_endpoint.h>
  22. #include <asiolink/udp_endpoint.h>
  23. using namespace std;
  24. namespace asiolink {
  25. const IOEndpoint*
  26. IOEndpoint::create(const int protocol, const IOAddress& address,
  27. const unsigned short port)
  28. {
  29. if (protocol == IPPROTO_UDP) {
  30. return (new UDPEndpoint(address, port));
  31. } else if (protocol == IPPROTO_TCP) {
  32. return (new TCPEndpoint(address, port));
  33. }
  34. isc_throw(IOError,
  35. "IOEndpoint creation attempt for unsupported protocol: " <<
  36. protocol);
  37. }
  38. }