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

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

Issue 10095020: Allow socket API to send binary data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Jeremy's judgments. Antonits. Created 8 years, 8 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
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 <string> 9 #include <string>
10 10
(...skipping 13 matching lines...) Expand all
24 public: 24 public:
25 virtual ~Socket(); 25 virtual ~Socket();
26 26
27 // Returns true iff the socket was able to properly initialize itself. 27 // Returns true iff the socket was able to properly initialize itself.
28 virtual bool IsValid() = 0; 28 virtual bool IsValid() = 0;
29 29
30 // Returns net::OK if successful, or an error code otherwise. 30 // Returns net::OK if successful, or an error code otherwise.
31 virtual int Connect() = 0; 31 virtual int Connect() = 0;
32 virtual void Disconnect() = 0; 32 virtual void Disconnect() = 0;
33 33
34 // Returns a string representing what was able to be read without blocking. 34 // Returns the number of bytes read into the buffer, or a negative number if
35 // If it reads an empty string, or blocks... the behavior is 35 // an error occurred.
36 // indistinguishable! TODO(miket): this is awful. We should be returning a 36 virtual int Read(scoped_refptr<net::IOBuffer> io_buffer, int io_buffer_size);
37 // blob, and we should be giving the caller all needed information about
38 // what's happening with the read operation.
39 virtual std::string Read();
40 37
41 // Returns the number of bytes successfully written, or a negative error 38 // Returns the number of bytes successfully written, or a negative error
42 // code. Note that ERR_IO_PENDING means that the operation blocked, in which 39 // code. Note that ERR_IO_PENDING means that the operation blocked, in which
43 // case |event_notifier| will eventually be called with the final result 40 // case |event_notifier| (supplied at socket creation) will eventually be
44 // (again, either a nonnegative number of bytes written, or a negative 41 // called with the final result (again, either a nonnegative number of bytes
45 // error). 42 // written, or a negative error).
46 virtual int Write(const std::string& message); 43 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int bytes);
47 44
48 virtual void OnDataRead(int result); 45 virtual void OnDataRead(scoped_refptr<net::IOBuffer> io_buffer, int result);
49 virtual void OnWriteComplete(int result); 46 virtual void OnWriteComplete(int result);
50 47
51 protected: 48 protected:
52 Socket(const std::string& address, int port, 49 Socket(const std::string& address, int port,
53 APIResourceEventNotifier* event_notifier); 50 APIResourceEventNotifier* event_notifier);
54 virtual net::Socket* socket() = 0; 51 virtual net::Socket* socket() = 0;
55 52
56 const std::string address_; 53 const std::string address_;
57 int port_; 54 int port_;
58 bool is_connected_; 55 bool is_connected_;
59
60 private:
61 static const int kMaxRead = 1024;
62 scoped_refptr<net::IOBufferWithSize> read_buffer_;
63 }; 56 };
64 57
65 } // namespace extensions 58 } // namespace extensions
66 59
67 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ 60 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/serial/serial_api.cc ('k') | chrome/browser/extensions/api/socket/socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698