| 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 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 | 1565 |
| 1566 class Win32Socket : public Socket { | 1566 class Win32Socket : public Socket { |
| 1567 public: | 1567 public: |
| 1568 explicit Win32Socket() { | 1568 explicit Win32Socket() { |
| 1569 // Create the socket. | 1569 // Create the socket. |
| 1570 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 1570 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 1571 } | 1571 } |
| 1572 explicit Win32Socket(SOCKET socket): socket_(socket) { } | 1572 explicit Win32Socket(SOCKET socket): socket_(socket) { } |
| 1573 | 1573 |
| 1574 | 1574 |
| 1575 virtual ~Win32Socket() { | 1575 virtual ~Win32Socket() { Close(); } |
| 1576 if (IsValid()) { | |
| 1577 // Close socket. | |
| 1578 closesocket(socket_); | |
| 1579 } | |
| 1580 } | |
| 1581 | 1576 |
| 1582 // Server initialization. | 1577 // Server initialization. |
| 1583 bool Bind(const int port); | 1578 bool Bind(const int port); |
| 1584 bool Listen(int backlog) const; | 1579 bool Listen(int backlog) const; |
| 1585 Socket* Accept() const; | 1580 Socket* Accept() const; |
| 1586 | 1581 |
| 1587 // Client initialization. | 1582 // Client initialization. |
| 1588 bool Connect(const char* host, const char* port); | 1583 bool Connect(const char* host, const char* port); |
| 1589 | 1584 |
| 1585 // Close. |
| 1586 bool Close(); |
| 1587 |
| 1590 // Data Transimission | 1588 // Data Transimission |
| 1591 int Send(const char* data, int len) const; | 1589 int Send(const char* data, int len) const; |
| 1592 int Receive(char* data, int len) const; | 1590 int Receive(char* data, int len) const; |
| 1593 | 1591 |
| 1594 bool IsValid() const { return socket_ != INVALID_SOCKET; } | 1592 bool IsValid() const { return socket_ != INVALID_SOCKET; } |
| 1595 | 1593 |
| 1596 private: | 1594 private: |
| 1597 SOCKET socket_; | 1595 SOCKET socket_; |
| 1598 }; | 1596 }; |
| 1599 | 1597 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 if (status != 0) { | 1653 if (status != 0) { |
| 1656 return false; | 1654 return false; |
| 1657 } | 1655 } |
| 1658 | 1656 |
| 1659 // Connect. | 1657 // Connect. |
| 1660 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 1658 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
| 1661 return status == 0; | 1659 return status == 0; |
| 1662 } | 1660 } |
| 1663 | 1661 |
| 1664 | 1662 |
| 1663 bool Win32Socket::Close() { |
| 1664 if (IsValid()) { |
| 1665 // Close socket. |
| 1666 int rc = closesocket(socket_); |
| 1667 socket_ = INVALID_SOCKET; |
| 1668 return rc != SOCKET_ERROR; |
| 1669 } |
| 1670 return true; |
| 1671 } |
| 1672 |
| 1673 |
| 1665 int Win32Socket::Send(const char* data, int len) const { | 1674 int Win32Socket::Send(const char* data, int len) const { |
| 1666 int status = send(socket_, data, len, 0); | 1675 int status = send(socket_, data, len, 0); |
| 1667 return status; | 1676 return status; |
| 1668 } | 1677 } |
| 1669 | 1678 |
| 1670 | 1679 |
| 1671 int Win32Socket::Receive(char* data, int len) const { | 1680 int Win32Socket::Receive(char* data, int len) const { |
| 1672 int status = recv(socket_, data, len, 0); | 1681 int status = recv(socket_, data, len, 0); |
| 1673 return status; | 1682 return status; |
| 1674 } | 1683 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 | 1838 |
| 1830 // Release the thread handles | 1839 // Release the thread handles |
| 1831 CloseHandle(data_->sampler_thread_); | 1840 CloseHandle(data_->sampler_thread_); |
| 1832 CloseHandle(data_->profiled_thread_); | 1841 CloseHandle(data_->profiled_thread_); |
| 1833 } | 1842 } |
| 1834 | 1843 |
| 1835 | 1844 |
| 1836 #endif // ENABLE_LOGGING_AND_PROFILING | 1845 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1837 | 1846 |
| 1838 } } // namespace v8::internal | 1847 } } // namespace v8::internal |
| OLD | NEW |