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 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 // Client initialization. | 1558 // Client initialization. |
1559 bool Connect(const char* host, const char* port); | 1559 bool Connect(const char* host, const char* port); |
1560 | 1560 |
1561 // Shutdown socket for both read and write. | 1561 // Shutdown socket for both read and write. |
1562 bool Shutdown(); | 1562 bool Shutdown(); |
1563 | 1563 |
1564 // Data Transimission | 1564 // Data Transimission |
1565 int Send(const char* data, int len) const; | 1565 int Send(const char* data, int len) const; |
1566 int Receive(char* data, int len) const; | 1566 int Receive(char* data, int len) const; |
1567 | 1567 |
| 1568 bool SetReuseAddress(bool reuse_address); |
| 1569 |
1568 bool IsValid() const { return socket_ != INVALID_SOCKET; } | 1570 bool IsValid() const { return socket_ != INVALID_SOCKET; } |
1569 | 1571 |
1570 private: | 1572 private: |
1571 SOCKET socket_; | 1573 SOCKET socket_; |
1572 }; | 1574 }; |
1573 | 1575 |
1574 | 1576 |
1575 bool Win32Socket::Bind(const int port) { | 1577 bool Win32Socket::Bind(const int port) { |
1576 if (!IsValid()) { | 1578 if (!IsValid()) { |
1577 return false; | 1579 return false; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 return status; | 1656 return status; |
1655 } | 1657 } |
1656 | 1658 |
1657 | 1659 |
1658 int Win32Socket::Receive(char* data, int len) const { | 1660 int Win32Socket::Receive(char* data, int len) const { |
1659 int status = recv(socket_, data, len, 0); | 1661 int status = recv(socket_, data, len, 0); |
1660 return status; | 1662 return status; |
1661 } | 1663 } |
1662 | 1664 |
1663 | 1665 |
| 1666 bool Win32Socket::SetReuseAddress(bool reuse_address) { |
| 1667 BOOL on = reuse_address ? TRUE : FALSE; |
| 1668 int status = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, |
| 1669 reinterpret_cast<char*>(&on), sizeof(on)); |
| 1670 return status == SOCKET_ERROR; |
| 1671 } |
| 1672 |
| 1673 |
1664 bool Socket::Setup() { | 1674 bool Socket::Setup() { |
1665 // Initialize Winsock32 | 1675 // Initialize Winsock32 |
1666 int err; | 1676 int err; |
1667 WSADATA winsock_data; | 1677 WSADATA winsock_data; |
1668 WORD version_requested = MAKEWORD(1, 0); | 1678 WORD version_requested = MAKEWORD(1, 0); |
1669 err = WSAStartup(version_requested, &winsock_data); | 1679 err = WSAStartup(version_requested, &winsock_data); |
1670 if (err != 0) { | 1680 if (err != 0) { |
1671 PrintF("Unable to initialize Winsock, err = %d\n", Socket::LastError()); | 1681 PrintF("Unable to initialize Winsock, err = %d\n", Socket::LastError()); |
1672 } | 1682 } |
1673 | 1683 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 | 1826 |
1817 // Release the thread handles | 1827 // Release the thread handles |
1818 CloseHandle(data_->sampler_thread_); | 1828 CloseHandle(data_->sampler_thread_); |
1819 CloseHandle(data_->profiled_thread_); | 1829 CloseHandle(data_->profiled_thread_); |
1820 } | 1830 } |
1821 | 1831 |
1822 | 1832 |
1823 #endif // ENABLE_LOGGING_AND_PROFILING | 1833 #endif // ENABLE_LOGGING_AND_PROFILING |
1824 | 1834 |
1825 } } // namespace v8::internal | 1835 } } // namespace v8::internal |
OLD | NEW |