tcpsession.h
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. #ifndef _TCP_SESSION_H
  12. #define _TCP_SESSION_H
  13. #include "icqsession.h"
  14. #include "tcpsessionbase.h"
  15. #define TCP_PACKET_SIZE 4096
  16. #define TCP_HELLO 1
  17. enum {
  18. TCP_STATUS_NOT_CONN,
  19. TCP_STATUS_SOCKS_METHOD,
  20. TCP_STATUS_SOCKS_AUTH,
  21. TCP_STATUS_SOCKS_CONNECT,
  22. TCP_STATUS_HELLO_WAIT,
  23. TCP_STATUS_ESTABLISHED,
  24. };
  25. class TcpInPacket;
  26. class TcpSession : public IcqSession, public TcpSessionBase {
  27. public:
  28. TcpSession(IcqLink *link, const char *name, uint32 uin);
  29. virtual ~TcpSession();
  30. virtual IcqLinkBase *getLink() {
  31. return icqLink;
  32. }
  33. virtual int getSocket() {
  34. return sock;
  35. }
  36. virtual uint32 getRemoteUIN() {
  37. return uin;
  38. }
  39. virtual void setListener(TcpSessionListener *l) {
  40. listener = l;
  41. }
  42. virtual void destroy();
  43. virtual void shutdown();
  44. virtual bool isSendSession() {
  45. return isSend;
  46. }
  47. virtual void enableWrite();
  48. virtual OutPacket *createPacket(uint16 cmd);
  49. virtual bool sendPacket(OutPacket *out);
  50. virtual void onConnect(bool success);
  51. virtual bool onReceive();
  52. virtual void onSend();
  53. virtual void onClose();
  54. bool connect(uint32 ip, uint16 port, bool isSend);
  55. int sock;
  56. int status;
  57. private:
  58. bool onPacketReceived(TcpInPacket &);
  59. void createPlugin();
  60. int sendDirect(OutPacket *out);
  61. bool recvPacket();
  62. bool onTcpEstablished();
  63. TcpSessionListener *listener;
  64. bool isSend;
  65. uint32 destIP;
  66. uint16 destPort;
  67. uint32 realIP;
  68. char buf[TCP_PACKET_SIZE];
  69. int bufSize;
  70. };
  71. #endif