| 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 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 591 |
| 592 | 592 |
| 593 virtual ~MacOSSocket() { | 593 virtual ~MacOSSocket() { |
| 594 if (IsValid()) { | 594 if (IsValid()) { |
| 595 // Close socket. | 595 // Close socket. |
| 596 close(socket_); | 596 close(socket_); |
| 597 } | 597 } |
| 598 } | 598 } |
| 599 | 599 |
| 600 // Server initialization. | 600 // Server initialization. |
| 601 bool Bind (const int port); | 601 bool Bind(const int port); |
| 602 bool Listen(int backlog) const; | 602 bool Listen(int backlog) const; |
| 603 Socket* Accept () const; | 603 Socket* Accept() const; |
| 604 | 604 |
| 605 // Client initialization. | 605 // Client initialization. |
| 606 bool Connect(const char* host, const char* port); | 606 bool Connect(const char* host, const char* port); |
| 607 | 607 |
| 608 // Data Transimission | 608 // Data Transimission |
| 609 int Send(const char* data, int len) const; | 609 int Send(const char* data, int len) const; |
| 610 bool SendAll(const char* data, int len) const; | 610 bool SendAll(const char* data, int len) const; |
| 611 int Receive(char* data, int len) const; | 611 int Receive(char* data, int len) const; |
| 612 | 612 |
| 613 bool IsValid() const { return socket_ != -1; } | 613 bool IsValid() const { return socket_ != -1; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 628 return false; | 628 return false; |
| 629 } | 629 } |
| 630 | 630 |
| 631 sockaddr_in addr; | 631 sockaddr_in addr; |
| 632 memset(&addr, 0, sizeof(addr)); | 632 memset(&addr, 0, sizeof(addr)); |
| 633 addr.sin_family = AF_INET; | 633 addr.sin_family = AF_INET; |
| 634 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 634 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
| 635 addr.sin_port = htons(port); | 635 addr.sin_port = htons(port); |
| 636 status = bind(socket_, | 636 status = bind(socket_, |
| 637 reinterpret_cast<struct sockaddr *>(&addr), | 637 reinterpret_cast<struct sockaddr *>(&addr), |
| 638 sizeof (addr)); | 638 sizeof(addr)); |
| 639 return status == 0; | 639 return status == 0; |
| 640 } | 640 } |
| 641 | 641 |
| 642 | 642 |
| 643 bool MacOSSocket::Listen(int backlog) const { | 643 bool MacOSSocket::Listen(int backlog) const { |
| 644 if (!IsValid()) { | 644 if (!IsValid()) { |
| 645 return false; | 645 return false; |
| 646 } | 646 } |
| 647 | 647 |
| 648 int status = listen(socket_, backlog); | 648 int status = listen(socket_, backlog); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 673 struct addrinfo *result = NULL; | 673 struct addrinfo *result = NULL; |
| 674 struct addrinfo hints; | 674 struct addrinfo hints; |
| 675 memset(&hints, 0, sizeof(addrinfo)); | 675 memset(&hints, 0, sizeof(addrinfo)); |
| 676 hints.ai_family = AF_INET; | 676 hints.ai_family = AF_INET; |
| 677 hints.ai_socktype = SOCK_STREAM; | 677 hints.ai_socktype = SOCK_STREAM; |
| 678 hints.ai_protocol = IPPROTO_TCP; | 678 hints.ai_protocol = IPPROTO_TCP; |
| 679 int status = getaddrinfo(host, port, &hints, &result); | 679 int status = getaddrinfo(host, port, &hints, &result); |
| 680 if (status != 0) { | 680 if (status != 0) { |
| 681 return false; | 681 return false; |
| 682 } | 682 } |
| 683 | 683 |
| 684 // Connect. | 684 // Connect. |
| 685 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 685 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
| 686 return status == 0; | 686 return status == 0; |
| 687 } | 687 } |
| 688 | 688 |
| 689 | 689 |
| 690 int MacOSSocket::Send(const char* data, int len) const { | 690 int MacOSSocket::Send(const char* data, int len) const { |
| 691 int status = send(socket_, data, len, 0); | 691 int status = send(socket_, data, len, 0); |
| 692 return status; | 692 return status; |
| 693 } | 693 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } | 841 } |
| 842 | 842 |
| 843 // This sampler is no longer the active sampler. | 843 // This sampler is no longer the active sampler. |
| 844 active_sampler_ = NULL; | 844 active_sampler_ = NULL; |
| 845 active_ = false; | 845 active_ = false; |
| 846 } | 846 } |
| 847 | 847 |
| 848 #endif // ENABLE_LOGGING_AND_PROFILING | 848 #endif // ENABLE_LOGGING_AND_PROFILING |
| 849 | 849 |
| 850 } } // namespace v8::internal | 850 } } // namespace v8::internal |
| OLD | NEW |