标签:style blog http color 使用 os strong 数据
定义?
Class TCPConnection
{
public:
TCPConnection();
void activeOPen();
void passiveOpen();
void close();
void send();
protected:
friend class TCPState;
void changeState(TCPState* state);
private:
TCPState* m_state;
};
TCPConnection::TCPConnection()
{
m_state = TCPClosed::instance();
}
void TCPConnection::activeOpen()
{
m_state->activeOpen();
}
void TCPConnection::passiveOpen()
{
m_state->passiveOpen();
}
void TCPConnection::close()
{
m_state->close();
}
void TCPConnection::send()
{
m_state->send();
}
void changeState(TCPState* state)
{
m_state = state;
}
class TCPState
{
public:
virutal void activeOPen(TCPConnection*);
virtual void passiveOpen(TCPConnection*)
virtual void close(TCPConnection*);
virtual void send(TCPConnection*);
protected:
void changeState(TCPConnection*, TCPState*);
};
class TCPEStablished : public TCPState
{
public:
static TCPState* instance();
virtual void close(TCPConnection* t)
{
changeState(t, TCPConnection::instance());
}
};
class TCPListen : public TCPState
{
public:
static TCPListen* instance();
vritual void send(TCPConnection* t)
{
// send SYN, receive SYN, ACK, ect.
changeState(t, TCPEStabiished::instance());
}
};
class TCPClosed : public TCPState
{
public:
virtual void activeOpen(TCPConnection* t)
{
// send SYN, receive SYN, ACK, ect.
changeState(t, TCPEStablished::instance());
}
virtual void passiveOpen(TCPConnection* t)
{
// send FIN, receive ACK of FIN.
changeState(t, TCPListen::instance());
}
};
标签:style blog http color 使用 os strong 数据
原文地址:http://blog.csdn.net/harrising/article/details/38092017