1
0

listen.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. ** JNetLib
  3. ** Copyright (C) 2000-2013 Nullsoft, Inc.
  4. ** Author: Justin Frankel, Ben Allison
  5. ** File: listen.h - JNL interface for opening a TCP listen
  6. ** License: see jnetlib.h
  7. **
  8. ** Usage:
  9. ** 1. create a JNL_Listen object with the port and (optionally) the interface
  10. ** to listen on.
  11. ** 2. call get_connect() to get any new connections (optionally specifying what
  12. ** buffer sizes the connection should be created with)
  13. ** 3. check is_error() to see if an error has occured
  14. ** 4. call port() if you forget what port the listener is on.
  15. **
  16. */
  17. #ifndef _LISTEN_H_
  18. #define _LISTEN_H_
  19. #include "connection.h"
  20. #include "nswasabi/ReferenceCounted.h"
  21. class JNL_Listen : public ReferenceCountedBase<JNL_Listen>
  22. {
  23. public:
  24. JNL_Listen();
  25. ~JNL_Listen();
  26. int Initialize( unsigned short port, sockaddr *which_interface = 0, int family = PF_UNSPEC );
  27. int Initialize( struct addrinfo *address, size_t index );
  28. JNL_Connection *get_connect( size_t sendbufsize = 8192, size_t recvbufsize = 8192 );
  29. unsigned short get_port();
  30. int is_error( void ) { return ( m_socket < 0 ); }
  31. socklen_t get_address( sockaddr *address, socklen_t *address_len );
  32. protected:
  33. SOCKET m_socket;
  34. unsigned short m_port;
  35. };
  36. #endif //_LISTEN_H_