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

Side by Side Diff: chrome/browser/extensions/api/socket/socket.h

Issue 10310170: Improve socket.write() to make sure all data will be sent out. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update Created 8 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
7 #pragma once 7 #pragma once
8 8
9 #include <queue>
9 #include <string> 10 #include <string>
11 #include <utility>
10 12
11 #include "base/callback.h" 13 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/extensions/api/api_resource.h" 15 #include "chrome/browser/extensions/api/api_resource.h"
16 #include "net/base/completion_callback.h"
14 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
15 18
16 namespace net { 19 namespace net {
17 class AddressList; 20 class AddressList;
18 class IPEndPoint; 21 class IPEndPoint;
19 class Socket; 22 class Socket;
20 } 23 }
21 24
22 namespace extensions { 25 namespace extensions {
23 26
(...skipping 16 matching lines...) Expand all
40 const CompletionCallback& callback) = 0; 43 const CompletionCallback& callback) = 0;
41 virtual void Disconnect() = 0; 44 virtual void Disconnect() = 0;
42 45
43 virtual int Bind(const std::string& address, int port) = 0; 46 virtual int Bind(const std::string& address, int port) = 0;
44 47
45 // Returns the number of bytes read into the buffer, or a negative number if 48 // Returns the number of bytes read into the buffer, or a negative number if
46 // an error occurred. 49 // an error occurred.
47 virtual void Read(int count, 50 virtual void Read(int count,
48 const ReadCompletionCallback& callback) = 0; 51 const ReadCompletionCallback& callback) = 0;
49 52
50 // Returns the number of bytes successfully written, or a negative error 53 // Returns the number of bytes successfully written, or a negative error
jeremya 2012/05/17 01:09:06 Update comment.
Peng 2012/05/17 02:42:22 Will fix it tomorrow. I am home and can not access
Peng 2012/05/17 15:05:13 Done.
51 // code. Note that ERR_IO_PENDING means that the operation blocked, in which 54 // code. Note that ERR_IO_PENDING means that the operation blocked, in which
52 // case |event_notifier| (supplied at socket creation) will eventually be 55 // case |event_notifier| (supplied at socket creation) will eventually be
53 // called with the final result (again, either a nonnegative number of bytes 56 // called with the final result (again, either a nonnegative number of bytes
54 // written, or a negative error). 57 // written, or a negative error).
55 virtual void Write(scoped_refptr<net::IOBuffer> io_buffer, 58 void Write(scoped_refptr<net::IOBuffer> io_buffer,
56 int byte_count, 59 int byte_count,
57 const CompletionCallback& callback) = 0; 60 const CompletionCallback& callback);
58 61
59 virtual void RecvFrom(int count, 62 virtual void RecvFrom(int count,
60 const RecvFromCompletionCallback& callback) = 0; 63 const RecvFromCompletionCallback& callback) = 0;
61 64
62 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, 65 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
63 int byte_count, 66 int byte_count,
64 const std::string& address, 67 const std::string& address,
65 int port, 68 int port,
66 const CompletionCallback& callback) = 0; 69 const CompletionCallback& callback) = 0;
67 70
68 static bool StringAndPortToAddressList(const std::string& ip_address_str, 71 static bool StringAndPortToAddressList(const std::string& ip_address_str,
69 int port, 72 int port,
70 net::AddressList* address_list); 73 net::AddressList* address_list);
71 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str, 74 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str,
72 int port, 75 int port,
73 net::IPEndPoint* ip_end_point); 76 net::IPEndPoint* ip_end_point);
74 static void IPEndPointToStringAndPort(const net::IPEndPoint& address, 77 static void IPEndPointToStringAndPort(const net::IPEndPoint& address,
75 std::string* ip_address_str, 78 std::string* ip_address_str,
76 int* port); 79 int* port);
77 80
78 protected: 81 protected:
79 explicit Socket(APIResourceEventNotifier* event_notifier); 82 explicit Socket(APIResourceEventNotifier* event_notifier);
83
jeremya 2012/05/17 01:09:06 nit: extra blank line
Peng 2012/05/17 15:05:13 Done.
84
85 void WriteData();
86 virtual int WriteImpl(net::IOBuffer* io_buffer,
87 int io_buffer_size,
88 const net::CompletionCallback& callback) = 0;
89 virtual void OnWriteComplete(int result);
90
80 const std::string address_; 91 const std::string address_;
81 int port_; 92 int port_;
82 bool is_connected_; 93 bool is_connected_;
94
95 private:
96 struct WriteRequest {
97 WriteRequest(scoped_refptr<net::IOBuffer> io_buffer,
98 int byte_count,
99 const CompletionCallback& callback)
100 : io_buffer(io_buffer),
101 byte_count(byte_count),
102 callback(callback),
103 byte_written(0) {}
jeremya 2012/05/17 01:09:06 bytes_written
Peng 2012/05/17 15:05:13 Done.
104 scoped_refptr<net::IOBuffer> io_buffer;
105 int byte_count;
106 CompletionCallback callback;
107 int byte_written;
108 };
109 std::queue<WriteRequest> write_queue_;
110 scoped_refptr<net::IOBuffer> io_buffer_write_;
83 }; 111 };
84 112
85 } // namespace extensions 113 } // namespace extensions
86 114
87 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 115 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/socket/socket.cc » ('j') | chrome/browser/extensions/api/socket/socket.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698