if (bStoring) { // save signature ar << CString(lpszSignature); // Save the changed user details for (int i=0; i < m_UserArray.GetSize(); i++) { m_UserArray[i].Serialize(ar); } ar.Flush(); } else { // load signature ar >> str; // if this the file we are looking for ? if (str.Compare(lpszSignature) == 0) { int nCount=0; while(!ar.IsBufferEmpty()) { CUser user; // get user data user.Serialize(ar);
// add user to array m_UserArray.Add(user); } } } ar.Close(); file.Close(); } CATCH_ALL(e) { // catch all exceptions that might happen ... return FALSE; } END_CATCH_ALL
try { // Attach the socket handle to a CSocket object. // This makes sure that the socket notifications are sent to this thread. m_ConnectSocket.Attach(m_hSocket); m_ConnectSocket.m_pThread = this; CString strIPAddress; UINT nPort; m_ConnectSocket.GetPeerName(strIPAddress, nPort); // notify server that there's a new connection m_pWndServer->SendMessage(WM_THREADSTART, (WPARAM)this, 0);
if (((CFTPServer *)m_pWndServer)->CheckMaxUsers()) { m_ConnectSocket.SendResponse("421 Too many users are connected, please try again later."); PostThreadMessage(WM_QUIT,0,0); } else if (!((CFTPServer *)m_pWndServer)->IsIPAddressAllowed(strIPAddress)) { m_ConnectSocket.SendResponse("421 Access denied, IP address was rejected by the server."); PostThreadMessage(WM_QUIT,0,0); } else { // send welcome message to client CString strText = ((CFTPServer *)m_pWndServer)->GetWelcomeMessage(); m_ConnectSocket.SendResponse("220 " + strText); m_nTimerID = ::SetTimer(NULL, 0, 1000, TimerProc); } } catch(CException *e) { e->Delete(); } return TRUE;
catch(){//用于处理异常
}
{
CString str;
CArchive ar(&file, bStoring ? CArchive::store : CArchive::load);
if (bStoring)
{
// save signature
ar << CString(lpszSignature); // Save the changed user details
for (int i=0; i < m_UserArray.GetSize(); i++)
{
m_UserArray[i].Serialize(ar);
} ar.Flush();
}
else
{
// load signature
ar >> str;
// if this the file we are looking for ?
if (str.Compare(lpszSignature) == 0)
{
int nCount=0; while(!ar.IsBufferEmpty())
{
CUser user; // get user data
user.Serialize(ar);
// add user to array
m_UserArray.Add(user);
}
}
}
ar.Close();
file.Close();
}
CATCH_ALL(e)
{
// catch all exceptions that might happen ...
return FALSE;
}
END_CATCH_ALL
{
// Attach the socket handle to a CSocket object.
// This makes sure that the socket notifications are sent to this thread.
m_ConnectSocket.Attach(m_hSocket);
m_ConnectSocket.m_pThread = this; CString strIPAddress;
UINT nPort;
m_ConnectSocket.GetPeerName(strIPAddress, nPort); // notify server that there's a new connection
m_pWndServer->SendMessage(WM_THREADSTART, (WPARAM)this, 0);
if (((CFTPServer *)m_pWndServer)->CheckMaxUsers())
{
m_ConnectSocket.SendResponse("421 Too many users are connected, please try again later.");
PostThreadMessage(WM_QUIT,0,0);
}
else
if (!((CFTPServer *)m_pWndServer)->IsIPAddressAllowed(strIPAddress))
{
m_ConnectSocket.SendResponse("421 Access denied, IP address was rejected by the server.");
PostThreadMessage(WM_QUIT,0,0);
}
else
{
// send welcome message to client
CString strText = ((CFTPServer *)m_pWndServer)->GetWelcomeMessage();
m_ConnectSocket.SendResponse("220 " + strText);
m_nTimerID = ::SetTimer(NULL, 0, 1000, TimerProc);
}
}
catch(CException *e)
{
e->Delete();
}
return TRUE;
各个语句参量定义如下:
CATCH( exception_class, exception_object_pointer_name )
AND_CATCH( exception_class, exception_object_pointer_name )
THROW( exception_object_pointer )