PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/ti.Network/TCPServerSocket.h

http://github.com/appcelerator/titanium_desktop
C Header | 69 lines | 42 code | 12 blank | 15 comment | 0 complexity | 085dd20055fab58c7893e2d31d27db93 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Copyright (c) 2010 Appcelerator, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef TCPServerSocket_h
  17. #define TCPServerSocket_h
  18. #include <kroll/kroll.h>
  19. #include <Poco/Net/StreamSocket.h>
  20. #include <Poco/Net/SocketReactor.h>
  21. #include <Poco/Net/SocketAcceptor.h>
  22. #include <Poco/Net/SocketNotification.h>
  23. #include <Poco/NObserver.h>
  24. #include <Poco/RunnableAdapter.h>
  25. #include <Poco/Thread.h>
  26. namespace Titanium {
  27. class TCPServerSocketConnector {
  28. public:
  29. TCPServerSocketConnector(KMethodRef callback,Poco::Net::ServerSocket& socket,Poco::Net::SocketReactor& reactor);
  30. virtual ~TCPServerSocketConnector();
  31. void onAccept(Poco::Net::ReadableNotification* pNotification);
  32. private:
  33. KMethodRef callback;
  34. Poco::Net::ServerSocket& socket;
  35. Poco::Net::SocketReactor& reactor;
  36. };
  37. class TCPServerSocket : public StaticBoundObject {
  38. public:
  39. TCPServerSocket(KMethodRef callback);
  40. virtual ~TCPServerSocket();
  41. private:
  42. enum {
  43. BUFFER_SIZE = 1024
  44. };
  45. void ListenThread();
  46. void Listen(const ValueList& args, KValueRef result);
  47. void Close(const ValueList& args, KValueRef result);
  48. KMethodRef onCreate;
  49. Poco::Net::ServerSocket* socket;
  50. Poco::Net::SocketReactor reactor;
  51. TCPServerSocketConnector* acceptor;
  52. Poco::Thread listenThread;
  53. Poco::RunnableAdapter<TCPServerSocket>* listenAdapter;
  54. bool listening;
  55. };
  56. } // namespace Titanium
  57. #endif