io_endpoint.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/io_endpoint.h>
  22. #include <asiolink/tcp_endpoint.h>
  23. #include <asiolink/udp_endpoint.h>
  24. using namespace std;
  25. namespace asiolink {
  26. const IOEndpoint*
  27. IOEndpoint::create(const int protocol, const IOAddress& address,
  28. const unsigned short port)
  29. {
  30. if (protocol == IPPROTO_UDP) {
  31. return (new UDPEndpoint(address, port));
  32. } else if (protocol == IPPROTO_TCP) {
  33. return (new TCPEndpoint(address, port));
  34. }
  35. isc_throw(IOError,
  36. "IOEndpoint creation attempt for unsupported protocol: " <<
  37. protocol);
  38. }
  39. }