Solved

I/O Completion Ports

Posted on 2004-03-27
11
410 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
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video shows how use content aware, what it’s used for, and when to use it over other tools.

770 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