| 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 // MacOS socket support. | 569 // MacOS socket support. |
| 570 // | 570 // |
| 571 | 571 |
| 572 class MacOSSocket : public Socket { | 572 class MacOSSocket : public Socket { |
| 573 public: | 573 public: |
| 574 explicit MacOSSocket() { | 574 explicit MacOSSocket() { |
| 575 // Create the socket. | 575 // Create the socket. |
| 576 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 576 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 577 } | 577 } |
| 578 explicit MacOSSocket(int socket): socket_(socket) { } | 578 explicit MacOSSocket(int socket): socket_(socket) { } |
| 579 | 579 virtual ~MacOSSocket() { Shutdown(); } |
| 580 virtual ~MacOSSocket() { Close(); } | |
| 581 | 580 |
| 582 // Server initialization. | 581 // Server initialization. |
| 583 bool Bind(const int port); | 582 bool Bind(const int port); |
| 584 bool Listen(int backlog) const; | 583 bool Listen(int backlog) const; |
| 585 Socket* Accept() const; | 584 Socket* Accept() const; |
| 586 | 585 |
| 587 // Client initialization. | 586 // Client initialization. |
| 588 bool Connect(const char* host, const char* port); | 587 bool Connect(const char* host, const char* port); |
| 589 | 588 |
| 590 // Close. | 589 // Shutdown socket for both read and write. |
| 591 bool Close(); | 590 bool Shutdown(); |
| 592 | 591 |
| 593 // Data Transimission | 592 // Data Transimission |
| 594 int Send(const char* data, int len) const; | 593 int Send(const char* data, int len) const; |
| 595 int Receive(char* data, int len) const; | 594 int Receive(char* data, int len) const; |
| 596 | 595 |
| 597 bool IsValid() const { return socket_ != -1; } | 596 bool IsValid() const { return socket_ != -1; } |
| 598 | 597 |
| 599 private: | 598 private: |
| 600 int socket_; | 599 int socket_; |
| 601 }; | 600 }; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 return false; | 664 return false; |
| 666 } | 665 } |
| 667 | 666 |
| 668 // Connect. | 667 // Connect. |
| 669 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 668 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
| 670 freeaddrinfo(result); | 669 freeaddrinfo(result); |
| 671 return status == 0; | 670 return status == 0; |
| 672 } | 671 } |
| 673 | 672 |
| 674 | 673 |
| 675 bool MacOSSocket::Close() { | 674 bool MacOSSocket::Shutdown() { |
| 676 if (IsValid()) { | 675 if (IsValid()) { |
| 677 // Close socket. | 676 // Shutdown socket for both read and write. |
| 678 int status = close(socket_); | 677 int status = shutdown(socket_, SHUT_RDWR); |
| 678 close(socket_); |
| 679 socket_ = -1; | 679 socket_ = -1; |
| 680 return status == 0; | 680 return status == 0; |
| 681 } | 681 } |
| 682 return true; | 682 return true; |
| 683 } | 683 } |
| 684 | 684 |
| 685 | 685 |
| 686 int MacOSSocket::Send(const char* data, int len) const { | 686 int MacOSSocket::Send(const char* data, int len) const { |
| 687 int status = send(socket_, data, len, 0); | 687 int status = send(socket_, data, len, 0); |
| 688 return status; | 688 return status; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 } | 824 } |
| 825 | 825 |
| 826 // This sampler is no longer the active sampler. | 826 // This sampler is no longer the active sampler. |
| 827 active_sampler_ = NULL; | 827 active_sampler_ = NULL; |
| 828 active_ = false; | 828 active_ = false; |
| 829 } | 829 } |
| 830 | 830 |
| 831 #endif // ENABLE_LOGGING_AND_PROFILING | 831 #endif // ENABLE_LOGGING_AND_PROFILING |
| 832 | 832 |
| 833 } } // namespace v8::internal | 833 } } // namespace v8::internal |
| OLD | NEW |