Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 12-02-2004, 03:00 PM   #1
Syrinx
Junior Member
 
Join Date: Jun 2004
Posts: 25
Default DarkOne,Can you give me a hand

Code:
void OnAccept(const SOCKET DataSocket)
{
 LPFTPDSession FTPDSessionInfo = NULL;
 EnterCriticalSection(&LinkListSession);
 FTPDSessionInfo = GetInfo(DataSocket);
 LeaveCriticalSection(&LinkListSession);

 if (FTPDSessionInfo == NULL)
 {
	 return ;
 }
 SendReadyInfo(FTPDSessionInfo);
}

void OnWrite(const SOCKET DataSocket)
{
 LPFTPDSession FTPDSessionInfo = NULL;
 EnterCriticalSection(&LinkListSession);
 FTPDSessionInfo = GetInfo(DataSocket);
 LeaveCriticalSection(&LinkListSession);

 if (FTPDSessionInfo == NULL)
 {
	 return ;
 }

 switch(FTPDSessionInfo->TransferAction)
 {
     case DOWNLOADFILE:
		 printf("Send File\n");
		 SendFileContent(DataSocket,FTPDSessionInfo);
		 break;
	 case UPLOADFILE:
		 break;
     case LISTFILE:
         printf("Send List\n");
		 SendListContent(FTPDSessionInfo);
     default:
		 break;
 }
}


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
 if (uMsg == WM_LISTENSOCKET)
 {
	 switch(WSAGETSELECTEVENT(lParam))
	 {
		 case FD_ACCEPT:
			 if (!WSAGETSELECTERROR(lParam))
			 {
				 HandleIncomingConnection(wParam,hwnd);
			 }
			 break;
         case FD_CLOSE:
             break;
	 }
	 return 0;
 }

 if (uMsg == WM_CONTROLSOCKET)
 {
	 switch(WSAGETSELECTEVENT(lParam))
	 {
		 case FD_READ:
			 HandleCommand(wParam);
			 break;
         case FD_WRITE:
			 break;
         case FD_CLOSE:
			  FreeClientSession(wParam);
	          DecrementClientCount();
			  printf("ControlSocket %d Disconnected\n",wParam);
              break;
	 }
	 return 0;
 }

 if (uMsg == WM_DATASOCKET)
 {
	 switch(WSAGETSELECTEVENT(lParam))
	 {
		 case FD_ACCEPT:
			 printf("DataSocket %d Accepted\n",wParam);
			 OnAccept((SOCKET)wParam);
			 break;
         case FD_CONNECT:
			 printf("Data Socket %d Connected\n",wParam);
			 break;
		 case FD_READ:
			 break;
         case FD_WRITE:
			 printf("Data Socket %d Is Writable\n",wParam);
			 OnWrite((SOCKET)wParam);
			 printf("OnWrite Complete\n");
			 break;
         case FD_CLOSE:
			 printf("DataSocket %d Disconnected\n",wParam);
             break;
	 }
	 return 0;
 }
 return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

BOOL SendFileContent(const SOCKET DataSocket,LPFTPDSession FTPDSessionInfo)
{
 if (FTPDSessionInfo->FileHandle == INVALID_HANDLE_VALUE || FTPDSessionInfo->FileBuffer == NULL)
 {
	 return FALSE;
 }
 BOOL Flag = FALSE;
 DWORD ByteToRead = 0;

 if (FTPDSessionInfo->TransferBytes > 0)
 {
     if (myFileSeek(FTPDSessionInfo->FileHandle, FTPDSessionInfo->TransferBytes,FILE_BEGIN) == INVALID_SET_FILE_POINTER)
	 {
	       return FALSE;
	 }
	 printf("Reset %d\n",FTPDSessionInfo->TransferBytes);
 }

 while(TRUE)
 {
	 if (FTPDSessionInfo->PostedBytes == READYSEND)
	 {
	   if (!ReadFile(FTPDSessionInfo->FileHandle,FTPDSessionInfo->FileBuffer,1024,&ByteToRead,NULL))
 	   {
		   printf("POut Here\n");
		   break;
	   }
	   
 	   if (ByteToRead == 0)
	   {
		   printf("Out Here %d\n",GetLastError());
	 	   break;
	   }
	 }

	 int nByteSent = send(DataSocket,FTPDSessionInfo->FileBuffer,ByteToRead,0);
	 if (nByteSent == SOCKET_ERROR)
	 {
		 if (WSAGetLastError() != WSAEWOULDBLOCK)
         {
			 printf("Error\n");
			 break;
		 }
		 nByteSent = 0;
	 }

	 FTPDSessionInfo->TransferBytes += nByteSent;
	 if (FTPDSessionInfo->FileSize > 0)
	 {
		 FTPDSessionInfo->Completion = (float)FTPDSessionInfo->TransferBytes / FTPDSessionInfo->FileSize * 100;
	 }

	 if (nByteSent < (int)ByteToRead)
	 {
		 printf("Buffer Full\n");
		 return FALSE;
	 }
	 printf("%d:Post %d Bytes\n",DataSocket,FTPDSessionInfo->TransferBytes);
 }
 CleanUP Stuff
}
I try to code a ftpd with asynchronous functions,but I found a problem.whenevev the ftpd sends about 400K data thru data socket,the buffer is full,so I return(see the code SendFileContent()),but for my surprise,the ftpd won't generate a new FD_WRITE event for that data socket again even there is room for the buffer.
Can you take a glance and tell me what's wrong?

thanks a lot
Syrinx is offline  
Old 12-02-2004, 06:13 PM   #2
neoxed
Too much time...
FlashFXP Beta Tester
ioFTPD Scripter
 
Join Date: May 2003
Posts: 1,326
Default

Use the vBulletin [CODE] tags, it makes source much easier to read...

I edited your above post.
neoxed is offline  
Old 01-13-2005, 05:02 AM   #3
Syrinx
Junior Member
 
Join Date: Jun 2004
Posts: 25
Default

I fixed that problem now.
Syrinx is offline  
Closed Thread

Tags
break;, case, ftpdsessioninfo, return, socket

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:54 PM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)