Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: src/platform-win32.cc

Issue 42387: Change the socket close to shutdown (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-macos.cc ('k') | test/cctest/test-sockets.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // Win32 socket support. 1541 // Win32 socket support.
1542 // 1542 //
1543 1543
1544 class Win32Socket : public Socket { 1544 class Win32Socket : public Socket {
1545 public: 1545 public:
1546 explicit Win32Socket() { 1546 explicit Win32Socket() {
1547 // Create the socket. 1547 // Create the socket.
1548 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 1548 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
1549 } 1549 }
1550 explicit Win32Socket(SOCKET socket): socket_(socket) { } 1550 explicit Win32Socket(SOCKET socket): socket_(socket) { }
1551 1551 virtual ~Win32Socket() { Shutdown(); }
1552
1553 virtual ~Win32Socket() { Close(); }
1554 1552
1555 // Server initialization. 1553 // Server initialization.
1556 bool Bind(const int port); 1554 bool Bind(const int port);
1557 bool Listen(int backlog) const; 1555 bool Listen(int backlog) const;
1558 Socket* Accept() const; 1556 Socket* Accept() const;
1559 1557
1560 // Client initialization. 1558 // Client initialization.
1561 bool Connect(const char* host, const char* port); 1559 bool Connect(const char* host, const char* port);
1562 1560
1563 // Close. 1561 // Shutdown socket for both read and write.
1564 bool Close(); 1562 bool Shutdown();
1565 1563
1566 // Data Transimission 1564 // Data Transimission
1567 int Send(const char* data, int len) const; 1565 int Send(const char* data, int len) const;
1568 int Receive(char* data, int len) const; 1566 int Receive(char* data, int len) const;
1569 1567
1570 bool IsValid() const { return socket_ != INVALID_SOCKET; } 1568 bool IsValid() const { return socket_ != INVALID_SOCKET; }
1571 1569
1572 private: 1570 private:
1573 SOCKET socket_; 1571 SOCKET socket_;
1574 }; 1572 };
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 return false; 1630 return false;
1633 } 1631 }
1634 1632
1635 // Connect. 1633 // Connect.
1636 status = connect(socket_, result->ai_addr, result->ai_addrlen); 1634 status = connect(socket_, result->ai_addr, result->ai_addrlen);
1637 freeaddrinfo(result); 1635 freeaddrinfo(result);
1638 return status == 0; 1636 return status == 0;
1639 } 1637 }
1640 1638
1641 1639
1642 bool Win32Socket::Close() { 1640 bool Win32Socket::Shutdown() {
1643 if (IsValid()) { 1641 if (IsValid()) {
1644 // Close socket. 1642 // Shutdown socket for both read and write.
1645 int rc = closesocket(socket_); 1643 int status = shutdown(socket_, SD_BOTH);
1644 closesocket(socket_);
1646 socket_ = INVALID_SOCKET; 1645 socket_ = INVALID_SOCKET;
1647 return rc != SOCKET_ERROR; 1646 return status == SOCKET_ERROR;
1648 } 1647 }
1649 return true; 1648 return true;
1650 } 1649 }
1651 1650
1652 1651
1653 int Win32Socket::Send(const char* data, int len) const { 1652 int Win32Socket::Send(const char* data, int len) const {
1654 int status = send(socket_, data, len, 0); 1653 int status = send(socket_, data, len, 0);
1655 return status; 1654 return status;
1656 } 1655 }
1657 1656
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 1816
1818 // Release the thread handles 1817 // Release the thread handles
1819 CloseHandle(data_->sampler_thread_); 1818 CloseHandle(data_->sampler_thread_);
1820 CloseHandle(data_->profiled_thread_); 1819 CloseHandle(data_->profiled_thread_);
1821 } 1820 }
1822 1821
1823 1822
1824 #endif // ENABLE_LOGGING_AND_PROFILING 1823 #endif // ENABLE_LOGGING_AND_PROFILING
1825 1824
1826 } } // namespace v8::internal 1825 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-macos.cc ('k') | test/cctest/test-sockets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698