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 1565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 // Server initialization. | 1576 // Server initialization. |
1577 bool Bind(const int port); | 1577 bool Bind(const int port); |
1578 bool Listen(int backlog) const; | 1578 bool Listen(int backlog) const; |
1579 Socket* Accept() const; | 1579 Socket* Accept() const; |
1580 | 1580 |
1581 // Client initialization. | 1581 // Client initialization. |
1582 bool Connect(const char* host, const char* port); | 1582 bool Connect(const char* host, const char* port); |
1583 | 1583 |
1584 // Data Transimission | 1584 // Data Transimission |
1585 int Send(const char* data, int len) const; | 1585 int Send(const char* data, int len) const; |
1586 bool SendAll(const char* data, int len) const; | |
1587 int Receive(char* data, int len) const; | 1586 int Receive(char* data, int len) const; |
1588 | 1587 |
1589 bool IsValid() const { return socket_ != INVALID_SOCKET; } | 1588 bool IsValid() const { return socket_ != INVALID_SOCKET; } |
1590 | 1589 |
1591 private: | 1590 private: |
1592 SOCKET socket_; | 1591 SOCKET socket_; |
1593 }; | 1592 }; |
1594 | 1593 |
1595 | 1594 |
1596 bool Win32Socket::Bind(const int port) { | 1595 bool Win32Socket::Bind(const int port) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 return status == 0; | 1655 return status == 0; |
1657 } | 1656 } |
1658 | 1657 |
1659 | 1658 |
1660 int Win32Socket::Send(const char* data, int len) const { | 1659 int Win32Socket::Send(const char* data, int len) const { |
1661 int status = send(socket_, data, len, 0); | 1660 int status = send(socket_, data, len, 0); |
1662 return status; | 1661 return status; |
1663 } | 1662 } |
1664 | 1663 |
1665 | 1664 |
1666 bool Win32Socket::SendAll(const char* data, int len) const { | |
1667 int sent_len = 0; | |
1668 while (sent_len < len) { | |
1669 int status = Send(data, len); | |
1670 if (status <= 0) { | |
1671 return false; | |
1672 } | |
1673 sent_len += status; | |
1674 } | |
1675 return true; | |
1676 } | |
1677 | |
1678 | |
1679 int Win32Socket::Receive(char* data, int len) const { | 1665 int Win32Socket::Receive(char* data, int len) const { |
1680 int status = recv(socket_, data, len, 0); | 1666 int status = recv(socket_, data, len, 0); |
1681 return status; | 1667 return status; |
1682 } | 1668 } |
1683 | 1669 |
1684 | 1670 |
1685 bool Socket::Setup() { | 1671 bool Socket::Setup() { |
1686 // Initialize Winsock32 | 1672 // Initialize Winsock32 |
1687 int err; | 1673 int err; |
1688 WSADATA winsock_data; | 1674 WSADATA winsock_data; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 | 1823 |
1838 // Release the thread handles | 1824 // Release the thread handles |
1839 CloseHandle(data_->sampler_thread_); | 1825 CloseHandle(data_->sampler_thread_); |
1840 CloseHandle(data_->profiled_thread_); | 1826 CloseHandle(data_->profiled_thread_); |
1841 } | 1827 } |
1842 | 1828 |
1843 | 1829 |
1844 #endif // ENABLE_LOGGING_AND_PROFILING | 1830 #endif // ENABLE_LOGGING_AND_PROFILING |
1845 | 1831 |
1846 } } // namespace v8::internal | 1832 } } // namespace v8::internal |
OLD | NEW |