| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 NET_UDP_UDP_SOCKET_WIN_H_ | 5 #ifndef NET_UDP_UDP_SOCKET_WIN_H_ |
| 6 #define NET_UDP_UDP_SOCKET_WIN_H_ | 6 #define NET_UDP_UDP_SOCKET_WIN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <winsock2.h> | 9 #include <winsock2.h> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // (similar to getsockname) | 48 // (similar to getsockname) |
| 49 int GetLocalAddress(IPEndPoint* address) const; | 49 int GetLocalAddress(IPEndPoint* address) const; |
| 50 | 50 |
| 51 // IO: | 51 // IO: |
| 52 // Multiple outstanding read requests are not supported. | 52 // Multiple outstanding read requests are not supported. |
| 53 // Full duplex mode (reading and writing at the same time) is supported | 53 // Full duplex mode (reading and writing at the same time) is supported |
| 54 | 54 |
| 55 // Read from the socket. | 55 // Read from the socket. |
| 56 // Only usable from the client-side of a UDP socket, after the socket | 56 // Only usable from the client-side of a UDP socket, after the socket |
| 57 // has been connected. | 57 // has been connected. |
| 58 int Read(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); | |
| 59 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); | 58 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 60 | 59 |
| 61 // Write to the socket. | 60 // Write to the socket. |
| 62 // Only usable from the client-side of a UDP socket, after the socket | 61 // Only usable from the client-side of a UDP socket, after the socket |
| 63 // has been connected. | 62 // has been connected. |
| 64 int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); | 63 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
| 65 | 64 |
| 66 // Read from a socket and receive sender address information. | 65 // Read from a socket and receive sender address information. |
| 67 // |buf| is the buffer to read data into. | 66 // |buf| is the buffer to read data into. |
| 68 // |buf_len| is the maximum amount of data to read. | 67 // |buf_len| is the maximum amount of data to read. |
| 69 // |address| is a buffer provided by the caller for receiving the sender | 68 // |address| is a buffer provided by the caller for receiving the sender |
| 70 // address information about the received data. This buffer must be kept | 69 // address information about the received data. This buffer must be kept |
| 71 // alive by the caller until the callback is placed. | 70 // alive by the caller until the callback is placed. |
| 72 // |address_length| is a ptr to the length of the |address| buffer. This | 71 // |address_length| is a ptr to the length of the |address| buffer. This |
| 73 // is an input parameter containing the maximum size |address| can hold | 72 // is an input parameter containing the maximum size |address| can hold |
| 74 // and also an output parameter for the size of |address| upon completion. | 73 // and also an output parameter for the size of |address| upon completion. |
| 75 // |callback| the callback on completion of the Recv. | 74 // |callback| the callback on completion of the Recv. |
| 76 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. | 75 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. |
| 77 // If ERR_IO_PENDING is returned, the caller must keep |buf|, |address|, | 76 // If ERR_IO_PENDING is returned, the caller must keep |buf|, |address|, |
| 78 // and |address_length| alive until the callback is called. | 77 // and |address_length| alive until the callback is called. |
| 79 int RecvFrom(IOBuffer* buf, | 78 int RecvFrom(IOBuffer* buf, |
| 80 int buf_len, | 79 int buf_len, |
| 81 IPEndPoint* address, | 80 IPEndPoint* address, |
| 82 OldCompletionCallback* callback); | |
| 83 int RecvFrom(IOBuffer* buf, | |
| 84 int buf_len, | |
| 85 IPEndPoint* address, | |
| 86 const CompletionCallback& callback); | 81 const CompletionCallback& callback); |
| 87 | 82 |
| 88 // Send to a socket with a particular destination. | 83 // Send to a socket with a particular destination. |
| 89 // |buf| is the buffer to send | 84 // |buf| is the buffer to send |
| 90 // |buf_len| is the number of bytes to send | 85 // |buf_len| is the number of bytes to send |
| 91 // |address| is the recipient address. | 86 // |address| is the recipient address. |
| 92 // |address_length| is the size of the recipient address | 87 // |address_length| is the size of the recipient address |
| 93 // |callback| is the user callback function to call on complete. | 88 // |callback| is the user callback function to call on complete. |
| 94 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. | 89 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. |
| 95 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| | 90 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| |
| 96 // alive until the callback is called. | 91 // alive until the callback is called. |
| 97 int SendTo(IOBuffer* buf, | 92 int SendTo(IOBuffer* buf, |
| 98 int buf_len, | 93 int buf_len, |
| 99 const IPEndPoint& address, | 94 const IPEndPoint& address, |
| 100 OldCompletionCallback* callback); | 95 const CompletionCallback& callback); |
| 101 | 96 |
| 102 // Set the receive buffer size (in bytes) for the socket. | 97 // Set the receive buffer size (in bytes) for the socket. |
| 103 bool SetReceiveBufferSize(int32 size); | 98 bool SetReceiveBufferSize(int32 size); |
| 104 | 99 |
| 105 // Set the send buffer size (in bytes) for the socket. | 100 // Set the send buffer size (in bytes) for the socket. |
| 106 bool SetSendBufferSize(int32 size); | 101 bool SetSendBufferSize(int32 size); |
| 107 | 102 |
| 108 // Returns true if the socket is already connected or bound. | 103 // Returns true if the socket is already connected or bound. |
| 109 bool is_connected() const { return socket_ != INVALID_SOCKET; } | 104 bool is_connected() const { return socket_ != INVALID_SOCKET; } |
| 110 | 105 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 143 |
| 149 // Returns the OS error code (or 0 on success). | 144 // Returns the OS error code (or 0 on success). |
| 150 int CreateSocket(const IPEndPoint& address); | 145 int CreateSocket(const IPEndPoint& address); |
| 151 | 146 |
| 152 // Same as SendTo(), except that address is passed by pointer | 147 // Same as SendTo(), except that address is passed by pointer |
| 153 // instead of by reference. It is called from Write() with |address| | 148 // instead of by reference. It is called from Write() with |address| |
| 154 // set to NULL. | 149 // set to NULL. |
| 155 int SendToOrWrite(IOBuffer* buf, | 150 int SendToOrWrite(IOBuffer* buf, |
| 156 int buf_len, | 151 int buf_len, |
| 157 const IPEndPoint* address, | 152 const IPEndPoint* address, |
| 158 OldCompletionCallback* callback); | 153 const CompletionCallback& callback); |
| 159 | 154 |
| 160 int InternalConnect(const IPEndPoint& address); | 155 int InternalConnect(const IPEndPoint& address); |
| 161 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 156 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
| 162 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 157 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
| 163 | 158 |
| 164 int DoBind(const IPEndPoint& address); | 159 int DoBind(const IPEndPoint& address); |
| 165 int RandomBind(const IPEndPoint& address); | 160 int RandomBind(const IPEndPoint& address); |
| 166 | 161 |
| 167 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| | 162 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| |
| 168 // to an IPEndPoint and writes it to |address|. Returns true on success. | 163 // to an IPEndPoint and writes it to |address|. Returns true on success. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 IPEndPoint* recv_from_address_; | 196 IPEndPoint* recv_from_address_; |
| 202 | 197 |
| 203 // Cached copy of the current address we're sending to, if any. Used for | 198 // Cached copy of the current address we're sending to, if any. Used for |
| 204 // logging. | 199 // logging. |
| 205 scoped_ptr<IPEndPoint> send_to_address_; | 200 scoped_ptr<IPEndPoint> send_to_address_; |
| 206 | 201 |
| 207 // The buffer used by InternalWrite() to retry Write requests | 202 // The buffer used by InternalWrite() to retry Write requests |
| 208 scoped_refptr<IOBuffer> write_iobuffer_; | 203 scoped_refptr<IOBuffer> write_iobuffer_; |
| 209 | 204 |
| 210 // External callback; called when read is complete. | 205 // External callback; called when read is complete. |
| 211 OldCompletionCallback* old_read_callback_; | |
| 212 CompletionCallback read_callback_; | 206 CompletionCallback read_callback_; |
| 213 | 207 |
| 214 // External callback; called when write is complete. | 208 // External callback; called when write is complete. |
| 215 OldCompletionCallback* write_callback_; | 209 CompletionCallback write_callback_; |
| 216 | 210 |
| 217 BoundNetLog net_log_; | 211 BoundNetLog net_log_; |
| 218 | 212 |
| 219 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); | 213 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); |
| 220 }; | 214 }; |
| 221 | 215 |
| 222 } // namespace net | 216 } // namespace net |
| 223 | 217 |
| 224 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 218 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
| OLD | NEW |