| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 // | 655 // |
| 656 | 656 |
| 657 class LinuxSocket : public Socket { | 657 class LinuxSocket : public Socket { |
| 658 public: | 658 public: |
| 659 explicit LinuxSocket() { | 659 explicit LinuxSocket() { |
| 660 // Create the socket. | 660 // Create the socket. |
| 661 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 661 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 662 } | 662 } |
| 663 explicit LinuxSocket(int socket): socket_(socket) { } | 663 explicit LinuxSocket(int socket): socket_(socket) { } |
| 664 | 664 |
| 665 | 665 virtual ~LinuxSocket() { Close(); } |
| 666 virtual ~LinuxSocket() { | |
| 667 if (IsValid()) { | |
| 668 // Close socket. | |
| 669 close(socket_); | |
| 670 } | |
| 671 } | |
| 672 | 666 |
| 673 // Server initialization. | 667 // Server initialization. |
| 674 bool Bind(const int port); | 668 bool Bind(const int port); |
| 675 bool Listen(int backlog) const; | 669 bool Listen(int backlog) const; |
| 676 Socket* Accept() const; | 670 Socket* Accept() const; |
| 677 | 671 |
| 678 // Client initialization. | 672 // Client initialization. |
| 679 bool Connect(const char* host, const char* port); | 673 bool Connect(const char* host, const char* port); |
| 680 | 674 |
| 675 // Close. |
| 676 bool Close(); |
| 677 |
| 681 // Data Transimission | 678 // Data Transimission |
| 682 int Send(const char* data, int len) const; | 679 int Send(const char* data, int len) const; |
| 683 int Receive(char* data, int len) const; | 680 int Receive(char* data, int len) const; |
| 684 | 681 |
| 685 bool IsValid() const { return socket_ != -1; } | 682 bool IsValid() const { return socket_ != -1; } |
| 686 | 683 |
| 687 private: | 684 private: |
| 688 int socket_; | 685 int socket_; |
| 689 }; | 686 }; |
| 690 | 687 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 if (status != 0) { | 743 if (status != 0) { |
| 747 return false; | 744 return false; |
| 748 } | 745 } |
| 749 | 746 |
| 750 // Connect. | 747 // Connect. |
| 751 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 748 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
| 752 return status == 0; | 749 return status == 0; |
| 753 } | 750 } |
| 754 | 751 |
| 755 | 752 |
| 753 bool LinuxSocket::Close() { |
| 754 if (IsValid()) { |
| 755 // Close socket. |
| 756 int status = close(socket_); |
| 757 socket_ = -1; |
| 758 return status == 0; |
| 759 } |
| 760 return true; |
| 761 } |
| 762 |
| 763 |
| 756 int LinuxSocket::Send(const char* data, int len) const { | 764 int LinuxSocket::Send(const char* data, int len) const { |
| 757 int status = send(socket_, data, len, 0); | 765 int status = send(socket_, data, len, 0); |
| 758 return status; | 766 return status; |
| 759 } | 767 } |
| 760 | 768 |
| 761 | 769 |
| 762 int LinuxSocket::Receive(char* data, int len) const { | 770 int LinuxSocket::Receive(char* data, int len) const { |
| 763 int status = recv(socket_, data, len, 0); | 771 int status = recv(socket_, data, len, 0); |
| 764 return status; | 772 return status; |
| 765 } | 773 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 } | 902 } |
| 895 | 903 |
| 896 // This sampler is no longer the active sampler. | 904 // This sampler is no longer the active sampler. |
| 897 active_sampler_ = NULL; | 905 active_sampler_ = NULL; |
| 898 active_ = false; | 906 active_ = false; |
| 899 } | 907 } |
| 900 | 908 |
| 901 #endif // ENABLE_LOGGING_AND_PROFILING | 909 #endif // ENABLE_LOGGING_AND_PROFILING |
| 902 | 910 |
| 903 } } // namespace v8::internal | 911 } } // namespace v8::internal |
| OLD | NEW |