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 3 // found in the LICENSE file. 4 5 #ifndef NET_UDP_DATAGRAM_SERVER_SOCKET_H_ 6 #define NET_UDP_DATAGRAM_SERVER_SOCKET_H_ 7 #pragma once 8 9 #include "net/base/completion_callback.h" 10 #include "net/udp/datagram_socket.h" 11 12 namespace net { 13 14 class IPEndPoint; 15 class IOBuffer; 16 17 // A UDP Socket. 18 class DatagramServerSocket : public DatagramSocket { 19 public: 20 virtual ~DatagramServerSocket() {} 21 22 // Initialize this socket as a server socket listening at |address|. 23 // Returns a network error code. 24 virtual int Listen(const IPEndPoint& address) = 0; 25 26 // Read from a socket and receive sender address information. 27 // |buf| is the buffer to read data into. 28 // |buf_len| is the maximum amount of data to read. 29 // |address| is a buffer provided by the caller for receiving the sender 30 // address information about the received data. This buffer must be kept 31 // alive by the caller until the callback is placed. 32 // |address_length| is a ptr to the length of the |address| buffer. This 33 // is an input parameter containing the maximum size |address| can hold 34 // and also an output parameter for the size of |address| upon completion. 35 // |callback| the callback on completion of the Recv. 36 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. 37 // If ERR_IO_PENDING is returned, the caller must keep |buf|, |address|, 38 // and |address_length| alive until the callback is called. 39 virtual int RecvFrom(IOBuffer* buf, 40 int buf_len, 41 IPEndPoint* address, 42 CompletionCallback* callback) = 0; 43 44 // Send to a socket with a particular destination. 45 // |buf| is the buffer to send 46 // |buf_len| is the number of bytes to send 47 // |address| is the recipient address. 48 // |address_length| is the size of the recipient address 49 // |callback| is the user callback function to call on complete. 50 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. 51 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| 52 // alive until the callback is called. 53 virtual int SendTo(IOBuffer* buf, 54 int buf_len, 55 const IPEndPoint& address, 56 CompletionCallback* callback) = 0; 57 }; 58 59 } // namespace net 60 61 #endif // NET_UDP_DATAGRAM_SERVER_SOCKET_H_ 62