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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // Linux socket support. | 644 // Linux socket support. |
645 // | 645 // |
646 | 646 |
647 class LinuxSocket : public Socket { | 647 class LinuxSocket : public Socket { |
648 public: | 648 public: |
649 explicit LinuxSocket() { | 649 explicit LinuxSocket() { |
650 // Create the socket. | 650 // Create the socket. |
651 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 651 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
652 } | 652 } |
653 explicit LinuxSocket(int socket): socket_(socket) { } | 653 explicit LinuxSocket(int socket): socket_(socket) { } |
654 | 654 virtual ~LinuxSocket() { Shutdown(); } |
655 virtual ~LinuxSocket() { Close(); } | |
656 | 655 |
657 // Server initialization. | 656 // Server initialization. |
658 bool Bind(const int port); | 657 bool Bind(const int port); |
659 bool Listen(int backlog) const; | 658 bool Listen(int backlog) const; |
660 Socket* Accept() const; | 659 Socket* Accept() const; |
661 | 660 |
662 // Client initialization. | 661 // Client initialization. |
663 bool Connect(const char* host, const char* port); | 662 bool Connect(const char* host, const char* port); |
664 | 663 |
665 // Close. | 664 // Shutdown socket for both read and write. |
666 bool Close(); | 665 bool Shutdown(); |
667 | 666 |
668 // Data Transimission | 667 // Data Transimission |
669 int Send(const char* data, int len) const; | 668 int Send(const char* data, int len) const; |
670 int Receive(char* data, int len) const; | 669 int Receive(char* data, int len) const; |
671 | 670 |
672 bool IsValid() const { return socket_ != -1; } | 671 bool IsValid() const { return socket_ != -1; } |
673 | 672 |
674 private: | 673 private: |
675 int socket_; | 674 int socket_; |
676 }; | 675 }; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 return false; | 733 return false; |
735 } | 734 } |
736 | 735 |
737 // Connect. | 736 // Connect. |
738 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 737 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
739 freeaddrinfo(result); | 738 freeaddrinfo(result); |
740 return status == 0; | 739 return status == 0; |
741 } | 740 } |
742 | 741 |
743 | 742 |
744 bool LinuxSocket::Close() { | 743 bool LinuxSocket::Shutdown() { |
745 if (IsValid()) { | 744 if (IsValid()) { |
746 // Close socket. | 745 // Shutdown socket for both read and write. |
747 int status = close(socket_); | 746 int status = shutdown(socket_, SHUT_RDWR); |
| 747 close(socket_); |
748 socket_ = -1; | 748 socket_ = -1; |
749 return status == 0; | 749 return status == 0; |
750 } | 750 } |
751 return true; | 751 return true; |
752 } | 752 } |
753 | 753 |
754 | 754 |
755 int LinuxSocket::Send(const char* data, int len) const { | 755 int LinuxSocket::Send(const char* data, int len) const { |
756 int status = send(socket_, data, len, 0); | 756 int status = send(socket_, data, len, 0); |
757 return status; | 757 return status; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 } | 893 } |
894 | 894 |
895 // This sampler is no longer the active sampler. | 895 // This sampler is no longer the active sampler. |
896 active_sampler_ = NULL; | 896 active_sampler_ = NULL; |
897 active_ = false; | 897 active_ = false; |
898 } | 898 } |
899 | 899 |
900 #endif // ENABLE_LOGGING_AND_PROFILING | 900 #endif // ENABLE_LOGGING_AND_PROFILING |
901 | 901 |
902 } } // namespace v8::internal | 902 } } // namespace v8::internal |
OLD | NEW |