Click here to Skip to main content
16,012,316 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMultithreading Pin
RK_20001-Apr-02 10:10
RK_20001-Apr-02 10:10 
GeneralRe: Multithreading Pin
Tim Smith1-Apr-02 10:20
Tim Smith1-Apr-02 10:20 
GeneralRe: Multithreading Pin
Paul M Watt1-Apr-02 10:33
mentorPaul M Watt1-Apr-02 10:33 
GeneralRe: Multithreading Pin
lucy9-Apr-02 9:29
lucy9-Apr-02 9:29 
GeneralRe: Multithreading Pin
Bill Wilson1-Apr-02 12:47
Bill Wilson1-Apr-02 12:47 
GeneralTFTP Server and Windows Sockets Pin
1-Apr-02 9:53
suss1-Apr-02 9:53 
GeneralRe: TFTP Server and Windows Sockets Pin
Joaquín M López Muñoz1-Apr-02 10:13
Joaquín M López Muñoz1-Apr-02 10:13 
GeneralRe: TFTP Server and Windows Sockets Pin
1-Apr-02 10:20
suss1-Apr-02 10:20 
Here is where the code will spend most of it's time. This loop is sending the next block (512 byte size) of the file requested.
It calls SendBlock() listed below this loop.

The UpdateStatus, and all if it's formatting routines were disabled, just to see if that was the cause.

Sorry about the formatting, I can't seem to find the help on how to insert source code without losing the formatting from Visual Studio.

while (!m_bDone){
m_bCancelRetry = TRUE;
m_nRetryCount = 0;
//Sending a file
if (pbyData[0] == 0x00 && pbyData[1] == 0x04){
//ACK
if (pbyData[2] == HIBYTE(m_nBlockID) &&
pbyData[3] == LOBYTE(m_nBlockID)){
//ACK'd the last block we sent:
if (m_nBlockID == m_nLastBlockID){
m_nBlockID = -1;
AddReportString("Transfer complete.");
DWORD dwTime = GetTickCount();
CString szTime;
szTime.Format("Time to complete = %.2f seconds",(float) (((float)dwTime - (float)m_dwStartTime) / 1000));
AddReportString(szTime);
Abort();
}
else{
m_nBlockID++;
SendBlock();
}
}
else{
//Send the last block
//(no m_nBlockID++) increment here
SendBlock();
}
}
nResult = recvfrom(m_hSock,(char*)m_recvBuf,9126,0,&sockAddr,&nSockAddrLen);
if (nResult == SOCKET_ERROR){
DWORD dwErr = GetLastError();
CString szErr;
szErr.Format("RecvFrom() error = %08lX",dwErr);
AddReportString(szErr);
bErr = TRUE;
m_bDone = TRUE;
}
}



int CClientSock::SendBlock()
{
int nRet = 0;

m_bySend[0] = 0x00;
m_bySend[1] = 0x03; //Data
m_bySend[2] = HIBYTE(m_nBlockID);
m_bySend[3] = LOBYTE(m_nBlockID);

DWORD dwPos = (m_nBlockSize * (m_nBlockID - 1));

BYTE *pSrc = (m_FileData.GetData() + dwPos);

int nNum = m_nBlockSize;

if ((dwPos + nNum) > m_dwFileDataLength){
nNum = m_dwFileDataLength - dwPos;
}

memcpy(&(m_bySend[4]),pSrc,nNum);

sockaddr_in sockTo;
sockTo.sin_family = AF_INET;
int nToLen = sizeof(sockTo);
sockTo.sin_addr.s_addr = inet_addr((LPSTR)(LPCTSTR)m_szClientIP);
sockTo.sin_port = htons(m_nClientPort);

nRet = sendto(m_hSock,(char*)m_bySend,nNum + 4,0,(struct sockaddr*)&sockTo,nToLen);

if (nRet == SOCKET_ERROR){
DWORD dwErr = GetLastError();
CString szMsg;
szMsg.Format("Error %08lX found while sending file to client.",
dwErr);
AddReportString(szMsg);
}
else{
float pct = (float)(((float)dwPos / (float)m_dwFileDataLength) * 100.0);
CString szStat;
szStat.Format("%s: %lu bytes sent (%.0f%%)",m_szSendFile,dwPos,pct);
m_pServer->UpdateStatus(m_nSocketID,szStat);
}

return nRet;
}


GeneralRe: TFTP Server and Windows Sockets Pin
Dave_1-Apr-02 13:48
Dave_1-Apr-02 13:48 
GeneralFtp Upload Pin
Nnamdi Onyeyiri1-Apr-02 9:46
Nnamdi Onyeyiri1-Apr-02 9:46 
GeneralRe: Ftp Upload Pin
dazinith1-Apr-02 9:51
dazinith1-Apr-02 9:51 
GeneralRe: Ftp Upload Pin
Bill Wilson1-Apr-02 9:58
Bill Wilson1-Apr-02 9:58 
GeneralRe: Ftp Upload Pin
Nnamdi Onyeyiri1-Apr-02 23:54
Nnamdi Onyeyiri1-Apr-02 23:54 
Questionclistctrl question? Pin
jafrazee1-Apr-02 8:16
jafrazee1-Apr-02 8:16 
AnswerRe: clistctrl question? Pin
jafrazee1-Apr-02 9:17
jafrazee1-Apr-02 9:17 
QuestionCommand line parser for ATL or WTL? Pin
Todd Smith1-Apr-02 8:08
Todd Smith1-Apr-02 8:08 
AnswerRe: Command line parser for ATL or WTL? Pin
Tim Smith1-Apr-02 8:14
Tim Smith1-Apr-02 8:14 
AnswerRe: Command line parser for ATL or WTL? Pin
Chris Losinger1-Apr-02 8:22
professionalChris Losinger1-Apr-02 8:22 
GeneralRe: Command line parser for ATL or WTL? Pin
Todd Smith1-Apr-02 9:29
Todd Smith1-Apr-02 9:29 
GeneralIMPORTANT !!! READ THIS !!!! Pin
1-Apr-02 7:23
suss1-Apr-02 7:23 
GeneralRe: IMPORTANT !!! READ THIS !!!! Pin
dazinith1-Apr-02 8:01
dazinith1-Apr-02 8:01 
GeneralRe: IMPORTANT !!! READ THIS !!!! Pin
Nish Nishant1-Apr-02 8:13
sitebuilderNish Nishant1-Apr-02 8:13 
GeneralRe: IMPORTANT !!! READ THIS !!!! Pin
Philip Patrick1-Apr-02 11:59
professionalPhilip Patrick1-Apr-02 11:59 
GeneralRe: IMPORTANT !!! READ THIS !!!! Pin
Christian Graus1-Apr-02 11:14
protectorChristian Graus1-Apr-02 11:14 
GeneralRe: IMPORTANT !!! READ THIS !!!! Pin
Shog91-Apr-02 13:12
sitebuilderShog91-Apr-02 13:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.