| 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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 // | 666 // |
| 667 | 667 |
| 668 class FreeBSDSocket : public Socket { | 668 class FreeBSDSocket : public Socket { |
| 669 public: | 669 public: |
| 670 explicit FreeBSDSocket() { | 670 explicit FreeBSDSocket() { |
| 671 // Create the socket. | 671 // Create the socket. |
| 672 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 672 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 673 } | 673 } |
| 674 explicit FreeBSDSocket(int socket): socket_(socket) { } | 674 explicit FreeBSDSocket(int socket): socket_(socket) { } |
| 675 | 675 |
| 676 | 676 virtual ~FreeBSDSocket() { Close(); } |
| 677 virtual ~FreeBSDSocket() { | |
| 678 if (IsValid()) { | |
| 679 // Close socket. | |
| 680 close(socket_); | |
| 681 } | |
| 682 } | |
| 683 | 677 |
| 684 // Server initialization. | 678 // Server initialization. |
| 685 bool Bind(const int port); | 679 bool Bind(const int port); |
| 686 bool Listen(int backlog) const; | 680 bool Listen(int backlog) const; |
| 687 Socket* Accept() const; | 681 Socket* Accept() const; |
| 688 | 682 |
| 689 // Client initialization. | 683 // Client initialization. |
| 690 bool Connect(const char* host, const char* port); | 684 bool Connect(const char* host, const char* port); |
| 691 | 685 |
| 686 // Close. |
| 687 bool Close(); |
| 688 |
| 692 // Data Transimission | 689 // Data Transimission |
| 693 int Send(const char* data, int len) const; | 690 int Send(const char* data, int len) const; |
| 694 int Receive(char* data, int len) const; | 691 int Receive(char* data, int len) const; |
| 695 | 692 |
| 696 bool IsValid() const { return socket_ != -1; } | 693 bool IsValid() const { return socket_ != -1; } |
| 697 | 694 |
| 698 private: | 695 private: |
| 699 int socket_; | 696 int socket_; |
| 700 }; | 697 }; |
| 701 | 698 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 if (status != 0) { | 754 if (status != 0) { |
| 758 return false; | 755 return false; |
| 759 } | 756 } |
| 760 | 757 |
| 761 // Connect. | 758 // Connect. |
| 762 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 759 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
| 763 return status == 0; | 760 return status == 0; |
| 764 } | 761 } |
| 765 | 762 |
| 766 | 763 |
| 764 bool FreeBSDSocket::Close() { |
| 765 if (IsValid()) { |
| 766 // Close socket. |
| 767 int status = close(socket_); |
| 768 socket_ = -1; |
| 769 return status == 0; |
| 770 } |
| 771 return true; |
| 772 } |
| 773 |
| 767 int FreeBSDSocket::Send(const char* data, int len) const { | 774 int FreeBSDSocket::Send(const char* data, int len) const { |
| 768 int status = send(socket_, data, len, 0); | 775 int status = send(socket_, data, len, 0); |
| 769 return status; | 776 return status; |
| 770 } | 777 } |
| 771 | 778 |
| 772 | 779 |
| 773 int FreeBSDSocket::Receive(char* data, int len) const { | 780 int FreeBSDSocket::Receive(char* data, int len) const { |
| 774 int status = recv(socket_, data, len, 0); | 781 int status = recv(socket_, data, len, 0); |
| 775 return status; | 782 return status; |
| 776 } | 783 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 } | 912 } |
| 906 | 913 |
| 907 // This sampler is no longer the active sampler. | 914 // This sampler is no longer the active sampler. |
| 908 active_sampler_ = NULL; | 915 active_sampler_ = NULL; |
| 909 active_ = false; | 916 active_ = false; |
| 910 } | 917 } |
| 911 | 918 |
| 912 #endif // ENABLE_LOGGING_AND_PROFILING | 919 #endif // ENABLE_LOGGING_AND_PROFILING |
| 913 | 920 |
| 914 } } // namespace v8::internal | 921 } } // namespace v8::internal |
| OLD | NEW |