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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 // Server initialization. | 633 // Server initialization. |
634 bool Bind(const int port); | 634 bool Bind(const int port); |
635 bool Listen(int backlog) const; | 635 bool Listen(int backlog) const; |
636 Socket* Accept() const; | 636 Socket* Accept() const; |
637 | 637 |
638 // Client initialization. | 638 // Client initialization. |
639 bool Connect(const char* host, const char* port); | 639 bool Connect(const char* host, const char* port); |
640 | 640 |
641 // Data Transimission | 641 // Data Transimission |
642 int Send(const char* data, int len) const; | 642 int Send(const char* data, int len) const; |
643 bool SendAll(const char* data, int len) const; | |
644 int Receive(char* data, int len) const; | 643 int Receive(char* data, int len) const; |
645 | 644 |
646 bool IsValid() const { return socket_ != -1; } | 645 bool IsValid() const { return socket_ != -1; } |
647 | 646 |
648 private: | 647 private: |
649 int socket_; | 648 int socket_; |
650 }; | 649 }; |
651 | 650 |
652 | 651 |
653 bool LinuxSocket::Bind(const int port) { | 652 bool LinuxSocket::Bind(const int port) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 return status == 0; | 712 return status == 0; |
714 } | 713 } |
715 | 714 |
716 | 715 |
717 int LinuxSocket::Send(const char* data, int len) const { | 716 int LinuxSocket::Send(const char* data, int len) const { |
718 int status = send(socket_, data, len, 0); | 717 int status = send(socket_, data, len, 0); |
719 return status; | 718 return status; |
720 } | 719 } |
721 | 720 |
722 | 721 |
723 bool LinuxSocket::SendAll(const char* data, int len) const { | |
724 int sent_len = 0; | |
725 while (sent_len < len) { | |
726 int status = Send(data, len); | |
727 if (status <= 0) { | |
728 return false; | |
729 } | |
730 sent_len += status; | |
731 } | |
732 return true; | |
733 } | |
734 | |
735 | |
736 int LinuxSocket::Receive(char* data, int len) const { | 722 int LinuxSocket::Receive(char* data, int len) const { |
737 int status = recv(socket_, data, len, 0); | 723 int status = recv(socket_, data, len, 0); |
738 return status; | 724 return status; |
739 } | 725 } |
740 | 726 |
741 | 727 |
742 bool Socket::Setup() { | 728 bool Socket::Setup() { |
743 // Nothing to do on Linux. | 729 // Nothing to do on Linux. |
744 return true; | 730 return true; |
745 } | 731 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 } | 854 } |
869 | 855 |
870 // This sampler is no longer the active sampler. | 856 // This sampler is no longer the active sampler. |
871 active_sampler_ = NULL; | 857 active_sampler_ = NULL; |
872 active_ = false; | 858 active_ = false; |
873 } | 859 } |
874 | 860 |
875 #endif // ENABLE_LOGGING_AND_PROFILING | 861 #endif // ENABLE_LOGGING_AND_PROFILING |
876 | 862 |
877 } } // namespace v8::internal | 863 } } // namespace v8::internal |
OLD | NEW |