Solved

I/O Completion Ports

Posted on 2004-03-27
11
417 Views
Last Modified: 2013-11-15
I have been designing a windows ftp server with IOCPs model,but encountering some problems.
1.How to detect the time out(if some clients connected to the ftp server ,and never post any authorization data,the worker thread will not be notified).My current solution is to spawn an extra thread to check the time out of all connected clients,but it's not a good solution.
2.Is it possible to do the file transfer operation(download or upload) without spawning new threads for those clients requesting the "retr" or "stor" command.If it's possible,how would it be?
3.Is any good source code related to IOCPs rather than the echo server source code(the echo server source code is just too simple and  not taking the time out problem into account)

0
Comment
Question by:WinEggdDrop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10694708
1. If you are working with thread pool, the only way to detect idle client is to test all clients using special thread, as you do. I guess you have some class or structure associated with client, keep last client activity time there.
If you have worker thread for each client, setting timeout for wait operation (for example, GetQueuedCompletionStatus) detects idle client.

3. I learned a lot about IOCP from this sample:

http://www.codeproject.com/internet/winsockiocp.asp

It contains some minor bugs (like memory leaks), I spent some time to correct them. But it is good program to get general idea of IOCP programming.
0
 
LVL 22

Expert Comment

by:grg99
ID: 10694880
What's wrong with a helper thread?  You may want one anyway in order to update any current status display.

0
 

Author Comment

by:WinEggdDrop
ID: 10695051
http://www.codeproject.com/internet/winsockiocp.asp

It's buggy and it doesn't work at all(I doesn't modify any code),but the idea is good.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:WinEggdDrop
ID: 10696655
To grg99:
Nothing wrong with a helper thread,but assume I use singly linked list to store every request information,so every time I detect the time out, I have to go through the whole linked list(this list is shared data,I have to take a great care with some sort of critical session).If the linked list grows large,it just takes time,and as doing so,the new incoming connections will be blocked since the thread handling the incoming connections is unable to access the share data when detecting time out is in progress.
0
 

Author Comment

by:WinEggdDrop
ID: 10697307
To AlexFM:
     MSDN sdk's IOCP sample is better than that code,you can take a close look.
0
 
LVL 22

Expert Comment

by:grg99
ID: 10698498
>To grg99:
>Nothing wrong with a helper thread,but assume I use singly linked list to store every >request information,so every time I detect the time out, I have to go through the >whole linked list(this list is shared data,I have to take a great care with some sort of >critical session).If the linked list grows large,it just takes time,and as doing so,the >new incoming connections will be blocked since the thread handling the incoming >connections is unable to access the share data when detecting time out is in progress.

It should jsut take nanoseconds to compare a timeout value in each node, so I wouldnt worry about taking too much time with this.

It would be even easier if you'd organize the list with the oldest ones at the end, and reverse pointers so you can just peek at the end node and time it out as needed.  No searching required.

0
 
LVL 1

Accepted Solution

by:
mturk1 earned 500 total points
ID: 10821765
I'm not aware of your current design but the IOCP might not be the best solution since
you are building FTP server that is a state protocol.
The easiest solution is to have as many worker threads as the maximum allowed number of
connected users is, so in such cases you won't need the IOCP's at all but rather a thread
pool that you may pull off for each new connection.
The IOCP can be useful for a situations that you wish to create a huge amount of
allowed connected users, but that implies that you only have limited set of active transactions
going on. This mean that only 100 hundred users from for example 500 allowed can be served in
any point in time. So if happens that all 100 users are downloading a file then the rest 400 hundred
will be blocked out. This is not a very good design for FTP server thought.
So instead having IOCP that is meant to be used in stateless protocols like HTTP use the thread
pool instead with the configured number of maximum allowed connections.
You may further more make that thread pool dynamic from min to max to deal with not so frequent
connection bursts.

So in any case if you stick with the IOCP idea you will still need the array that will hold the
client info and it's size will be the size of a maximum allowed connected users.

In both cases you'll need to acquire the worker thread after the client connects, and then
use the read timeout using setsockopt. This value will give you the needed timeout.
There is no need to use the separate thread to monitor the timeout. It can be inherently obtained
using socket read timeouts

MT.
0
 

Author Comment

by:WinEggdDrop
ID: 12315201
To mturk1:
all You suggested are the multi-thread + blocking socket model,and I have already implemented a ftpd in that model,and it's pretty easy to accomplish,but what that model missing is scalable.IOCP isn't like you said above.I did a test on ftpd of each model,IOCP used less system resource,especially as the login users are huge(ect,1000 con-current connection)
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question