00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_OS_NET_DATAGRAMSOCKET_H 00025 #define MN_OS_NET_DATAGRAMSOCKET_H 00026 00027 /************************************************************* 00028 * Classes defined in this header file: 00029 * DatagramSocket 00030 */ 00031 00032 #include "MNSocket.h" 00033 #include "MNRope.h" 00034 #include "MNUDPServerSocket.h" 00035 #include "RefCountedSocketFactory.h" 00036 #include <sys/uio.h> 00037 #include <assert.h> 00038 00039 class MNSelector; 00040 class MNRope; 00041 00042 /* The Linux netinet header files are a shame, because they're completely 00043 * inconsitant compared to what the standards define. 00044 * Better check if this is defined in the 2.2.2 Kernel 00045 */ 00046 00047 #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/datagram */ 00048 00059 class DatagramSocket : public MNUDPServerSocket 00060 { 00061 private: 00062 void get_size_packet( ); 00063 00064 public: 00065 DatagramSocket( RefCountedSocketFactory* factory, 00066 MNSelector& sel, 00067 MNSocket& sock ); 00068 00069 DatagramSocket( RefCountedSocketFactory* factory, 00070 MNSelector& sel, 00071 int port ); 00072 00073 MNSocketBaseT<DatagramSocket> _callmeplease; 00074 MNSocketBaseT<DatagramSocket> _callmepleasewrite; 00075 virtual ~DatagramSocket ( ); 00076 00077 virtual void activate ( bool sender ); 00078 00082 virtual void tcp_callback ( MNSelector* select, int fd ); 00083 00090 virtual void write_enabled ( ); 00091 00095 struct iovec* set_buffers_tcp ( int& iovlen, int& buffersize ); 00096 00102 void buffers_to_rope_tcp ( struct iovec* iov, int& iovlen, size_t bytesused ); 00103 00104 private: 00105 int _packet_size; 00106 bool _size_packet; 00107 bool _data_packet; 00108 int _left_to_read; 00109 char* _size_packet_buffer; 00110 MNRope* _rope; 00111 }; 00112 00113 #endif /* MN_OS_NET_DATAGRAMSOCKET_H */ 00114 00115 00116