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 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 624 |
625 | 625 |
626 virtual ~LinuxSocket() { | 626 virtual ~LinuxSocket() { |
627 if (IsValid()) { | 627 if (IsValid()) { |
628 // Close socket. | 628 // Close socket. |
629 close(socket_); | 629 close(socket_); |
630 } | 630 } |
631 } | 631 } |
632 | 632 |
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; | 643 bool SendAll(const char* data, int len) const; |
644 int Receive(char* data, int len) const; | 644 int Receive(char* data, int len) const; |
645 | 645 |
646 bool IsValid() const { return socket_ != -1; } | 646 bool IsValid() const { return socket_ != -1; } |
647 | 647 |
648 private: | 648 private: |
649 int socket_; | 649 int socket_; |
650 }; | 650 }; |
651 | 651 |
652 | 652 |
653 bool LinuxSocket::Bind(const int port) { | 653 bool LinuxSocket::Bind(const int port) { |
654 if (!IsValid()) { | 654 if (!IsValid()) { |
655 return false; | 655 return false; |
656 } | 656 } |
657 | 657 |
658 sockaddr_in addr; | 658 sockaddr_in addr; |
659 memset(&addr, 0, sizeof(addr)); | 659 memset(&addr, 0, sizeof(addr)); |
660 addr.sin_family = AF_INET; | 660 addr.sin_family = AF_INET; |
661 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 661 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
662 addr.sin_port = htons(port); | 662 addr.sin_port = htons(port); |
663 int status = bind(socket_, | 663 int status = bind(socket_, |
664 reinterpret_cast<struct sockaddr *>(&addr), | 664 reinterpret_cast<struct sockaddr *>(&addr), |
665 sizeof (addr)); | 665 sizeof(addr)); |
666 return status == 0; | 666 return status == 0; |
667 } | 667 } |
668 | 668 |
669 | 669 |
670 bool LinuxSocket::Listen(int backlog) const { | 670 bool LinuxSocket::Listen(int backlog) const { |
671 if (!IsValid()) { | 671 if (!IsValid()) { |
672 return false; | 672 return false; |
673 } | 673 } |
674 | 674 |
675 int status = listen(socket_, backlog); | 675 int status = listen(socket_, backlog); |
(...skipping 24 matching lines...) Expand all Loading... |
700 struct addrinfo *result = NULL; | 700 struct addrinfo *result = NULL; |
701 struct addrinfo hints; | 701 struct addrinfo hints; |
702 memset(&hints, 0, sizeof(addrinfo)); | 702 memset(&hints, 0, sizeof(addrinfo)); |
703 hints.ai_family = AF_INET; | 703 hints.ai_family = AF_INET; |
704 hints.ai_socktype = SOCK_STREAM; | 704 hints.ai_socktype = SOCK_STREAM; |
705 hints.ai_protocol = IPPROTO_TCP; | 705 hints.ai_protocol = IPPROTO_TCP; |
706 int status = getaddrinfo(host, port, &hints, &result); | 706 int status = getaddrinfo(host, port, &hints, &result); |
707 if (status != 0) { | 707 if (status != 0) { |
708 return false; | 708 return false; |
709 } | 709 } |
710 | 710 |
711 // Connect. | 711 // Connect. |
712 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 712 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
713 return status == 0; | 713 return status == 0; |
714 } | 714 } |
715 | 715 |
716 | 716 |
717 int LinuxSocket::Send(const char* data, int len) const { | 717 int LinuxSocket::Send(const char* data, int len) const { |
718 int status = send(socket_, data, len, 0); | 718 int status = send(socket_, data, len, 0); |
719 return status; | 719 return status; |
720 } | 720 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 } | 868 } |
869 | 869 |
870 // This sampler is no longer the active sampler. | 870 // This sampler is no longer the active sampler. |
871 active_sampler_ = NULL; | 871 active_sampler_ = NULL; |
872 active_ = false; | 872 active_ = false; |
873 } | 873 } |
874 | 874 |
875 #endif // ENABLE_LOGGING_AND_PROFILING | 875 #endif // ENABLE_LOGGING_AND_PROFILING |
876 | 876 |
877 } } // namespace v8::internal | 877 } } // namespace v8::internal |
OLD | NEW |