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 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 | 1567 |
1568 | 1568 |
1569 virtual ~Win32Socket() { | 1569 virtual ~Win32Socket() { |
1570 if (IsValid()) { | 1570 if (IsValid()) { |
1571 // Close socket. | 1571 // Close socket. |
1572 closesocket(socket_); | 1572 closesocket(socket_); |
1573 } | 1573 } |
1574 } | 1574 } |
1575 | 1575 |
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; | 1586 bool SendAll(const char* data, int len) const; |
1587 int Receive(char* data, int len) const; | 1587 int Receive(char* data, int len) const; |
1588 | 1588 |
1589 bool IsValid() const { return socket_ != INVALID_SOCKET; } | 1589 bool IsValid() const { return socket_ != INVALID_SOCKET; } |
1590 | 1590 |
1591 private: | 1591 private: |
1592 SOCKET socket_; | 1592 SOCKET socket_; |
1593 }; | 1593 }; |
1594 | 1594 |
1595 | 1595 |
1596 bool Win32Socket::Bind(const int port) { | 1596 bool Win32Socket::Bind(const int port) { |
1597 if (!IsValid()) { | 1597 if (!IsValid()) { |
1598 return false; | 1598 return false; |
1599 } | 1599 } |
1600 | 1600 |
1601 sockaddr_in addr; | 1601 sockaddr_in addr; |
1602 memset(&addr, 0, sizeof(addr)); | 1602 memset(&addr, 0, sizeof(addr)); |
1603 addr.sin_family = AF_INET; | 1603 addr.sin_family = AF_INET; |
1604 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | 1604 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
1605 addr.sin_port = htons(port); | 1605 addr.sin_port = htons(port); |
1606 int status = bind(socket_, | 1606 int status = bind(socket_, |
1607 reinterpret_cast<struct sockaddr *>(&addr), | 1607 reinterpret_cast<struct sockaddr *>(&addr), |
1608 sizeof (addr)); | 1608 sizeof(addr)); |
1609 return status == 0; | 1609 return status == 0; |
1610 } | 1610 } |
1611 | 1611 |
1612 | 1612 |
1613 bool Win32Socket::Listen(int backlog) const { | 1613 bool Win32Socket::Listen(int backlog) const { |
1614 if (!IsValid()) { | 1614 if (!IsValid()) { |
1615 return false; | 1615 return false; |
1616 } | 1616 } |
1617 | 1617 |
1618 int status = listen(socket_, backlog); | 1618 int status = listen(socket_, backlog); |
(...skipping 24 matching lines...) Expand all Loading... |
1643 struct addrinfo *result = NULL; | 1643 struct addrinfo *result = NULL; |
1644 struct addrinfo hints; | 1644 struct addrinfo hints; |
1645 memset(&hints, 0, sizeof(addrinfo)); | 1645 memset(&hints, 0, sizeof(addrinfo)); |
1646 hints.ai_family = AF_INET; | 1646 hints.ai_family = AF_INET; |
1647 hints.ai_socktype = SOCK_STREAM; | 1647 hints.ai_socktype = SOCK_STREAM; |
1648 hints.ai_protocol = IPPROTO_TCP; | 1648 hints.ai_protocol = IPPROTO_TCP; |
1649 int status = getaddrinfo(host, port, &hints, &result); | 1649 int status = getaddrinfo(host, port, &hints, &result); |
1650 if (status != 0) { | 1650 if (status != 0) { |
1651 return false; | 1651 return false; |
1652 } | 1652 } |
1653 | 1653 |
1654 // Connect. | 1654 // Connect. |
1655 status = connect(socket_, result->ai_addr, result->ai_addrlen); | 1655 status = connect(socket_, result->ai_addr, result->ai_addrlen); |
1656 return status == 0; | 1656 return status == 0; |
1657 } | 1657 } |
1658 | 1658 |
1659 | 1659 |
1660 int Win32Socket::Send(const char* data, int len) const { | 1660 int Win32Socket::Send(const char* data, int len) const { |
1661 int status = send(socket_, data, len, 0); | 1661 int status = send(socket_, data, len, 0); |
1662 return status; | 1662 return status; |
1663 } | 1663 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 | 1837 |
1838 // Release the thread handles | 1838 // Release the thread handles |
1839 CloseHandle(data_->sampler_thread_); | 1839 CloseHandle(data_->sampler_thread_); |
1840 CloseHandle(data_->profiled_thread_); | 1840 CloseHandle(data_->profiled_thread_); |
1841 } | 1841 } |
1842 | 1842 |
1843 | 1843 |
1844 #endif // ENABLE_LOGGING_AND_PROFILING | 1844 #endif // ENABLE_LOGGING_AND_PROFILING |
1845 | 1845 |
1846 } } // namespace v8::internal | 1846 } } // namespace v8::internal |
OLD | NEW |