Socket.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - a simple utility for downloading files faster
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /* copyright --> */
  22. #include "Socket.h"
  23. Socket::Socket() {
  24. core = new SocketCore();
  25. }
  26. Socket::Socket(const Socket& s) {
  27. core = s.core;
  28. core->use++;
  29. }
  30. Socket::~Socket() {
  31. core->use--;
  32. if(core->use == 0) {
  33. delete core;
  34. }
  35. }
  36. Socket& Socket::operator=(const Socket& s) {
  37. if(this != &s) {
  38. core->use--;
  39. if(core->use == 0) {
  40. delete core;
  41. }
  42. core = s.core;
  43. core->use++;
  44. }
  45. return *this;
  46. }
  47. void Socket::establishConnection(string host, int port) {
  48. core->establishConnection(host, port);
  49. }
  50. void Socket::setNonBlockingMode() {
  51. core->setNonBlockingMode();
  52. }
  53. void Socket::closeConnection() {
  54. core->closeConnection();
  55. }
  56. bool Socket::isWritable(int timeout) {
  57. return core->isWritable(timeout);
  58. }
  59. bool Socket::isReadable(int timeout) {
  60. return core->isReadable(timeout);
  61. }
  62. void Socket::writeData(const char* data, int len, int timeout) {
  63. core->writeData(data, len, timeout);
  64. }
  65. void Socket::readData(char* data, int& len, int timeout) {
  66. core->readData(data, len, timeout);
  67. }
  68. void Socket::peekData(char* data, int& len, int timeout) {
  69. core->peekData(data, len, timeout);
  70. }
  71. #ifdef HAVE_LIBSSL
  72. // for SSL
  73. void Socket::initiateSecureConnection() {
  74. core->initiateSecureConnection();
  75. }
  76. #endif // HAVE_LIBSSL