Tam Sürümünü Görmek İçin : Asyn. vs Non Blocking Sockets
Merhabalar su anda uzerinde ugrasmakta oldugum bir projede topicte konu hakkında bir secim yapmak zorundayım.
Aslında sanırsam secimim yok ama yinede buraya yazmak istedim..
İhtiyac geregi bu 2 yoldan birini kullanmalıyım:
* Asyn.socket kullanıp Signallar vasıtasıyla socket eventlerinden haberdar olmak
* Non blocking sockets kullanıp belirli surelerde sistemi polllayarak yeni socket eventi varmı kontrol etmek. Bu yolda threading kullanarak; soket durumlarını pollayan fonksiyonu ayrı bir threada koymayı dusunuyorum..
Bunlar arasında bir secim yapmam lazım ama bu secim bazı seylere baglı;
Proje cross platform bir proje; ANSI C ile yazdıgımız bu projenin 2 target'ı var;
-> Microsoft VC++ 6
-> Gcc
Eger threading kullanmam gerekirse; lin ortamında pthreads , win icinde pthreads-win32 kullanmaya karar verdik
*nix socket ile winsockets arasında ki farklılıkları ise soyutlama yaparak asmayı dusunuyoruz.
Asıl sorum su; Windows Sockets'da her call icin bir de asyn. call oldugunu biliyorum.Ama sanırsma bu asyn. callar bizden window handle istiyor (sinyal-mesajları geri gonderebilmek icin) Haliyle cross-platform projemizde; winmain mevcut degil ve window handleımız yok.
Winsockets ile asyn. socket kullanabilmek icin window handle dısında bir yontem mevcut mu?
Siz hangi yontemi tercih ederdiniz. Gerekirse projenin networking core kısmının gereklerini acıklayabilirim..
acehreli
19/04/2004, 17:50
RaiST,
Eger 'threading'de karar kilarsaniz ve C++ kullanacaksaniz, bahsettigin soyutlama zaten yapilmis durumda. Boost'un 'threads' kutuphanesine bakabilirsin:
http://boost.org/libs/thread/doc/index.html
Hic olmazsa onlardan fikir edinebilirsiniz.
Ali
tesekkur ederim,
malasef proje C projesi.
Su anda nonblocking + pthreads (pthreads32) yontemını denemeye karar verdim. gelismeleri buraya yazacagım
Euclides
19/04/2004, 18:47
Selam RaiST;
1...
Tamhin ettiğim kadarıyla bir gözetleme programı yazıyorsun.bence bunun için daha uygun bir teknik kullanabilirsin. Windows'da "Filter Drivers" adlı bir çekirdek eklentisi tarzı var.Bu sayede NIDS'a gelen ve giden herşeyi gözlemleyebilir ve değişrebilirsin. Firewallar böyle çalışıyor. Detaylar için Windows DDK'ya bakabilirsin.İçinde örnekte olması lazım.
Linux'de de yine çekirdek eklentileri yardımıyla bunu yapabilrisin.bence böyel daha kolay olur.
2...
proje C projesi demişsin ama hedef derleyicilerde Visual C++ 6 var. Bu durumda C++ projesi.
Çünkü Vİsual C++ dosya uzantısı ne olursa olsun "New" komutunu tanıyor bir başka değişle hep c++ kullanıyor.
1- programram gozetleme programı degil oyle olsaydı direkt libncap vs kullanırdım..
2- visual c++ pure ANSI C derleme kabiliyetine sahiptir. proje yaratılması sırasında default templateleri es gecerek bunu yapabiliyoruz.. Sonucta projeyi GNU GCC ile pure C olarak derleyebiliyoruz ve mingcw de sorun yok.
Bu arada socket konusunda baya bir bilgi sahibi oldum ve bir dokuman arsivi olusturdum.
faq ve dokuman sayfası olusturmayı dusunuyorum
Euclides
19/04/2004, 19:34
örnek
test.c
-------
...
...
...
char *x=new char[100];
...
...
...
bu kod Dosya uzantısı .c olmasına rağmen Visual C++ ile derlendiğinde sorun çıkartmaz ama gcc ile derlendiğind error veriri demek istediğim buydu.
2...
linux ok ama hani win ? :)
acehreli
19/04/2004, 20:16
Euclides, birden fazla dili destekleyen her derleyicinin herhangi bir kutugu hangi dilde derlemesi gerektigini disaridan alabilmesi gerekir.
Derleyiciler, bu bilgi kendilerine verilmediginde kutuk uzantilarina bakarak karar verirler.
Herhangi uzantili bir kutugu gcc ile C++ derleyicisi gibi derleyebilmek icin -x secenegini kullanabilirsin. Ornegin, adi abc.xyz olan bir kutugu C++ kaynak kodu gibi derlemek icin:
gcc -x c++ abc.xyz
yazilabilir.
RaiST VC++ ile menuler yardimiyle ANSI C secebildigini zaten soyledi. VC++'ta eminim ayrica komut satiri secenekleri de kullanilabiliyordur.
Ali
Euclides
19/04/2004, 21:26
gcc için söyledikleriniz elbeteki doğru ama vc++ 6 için değil
"new" tagınını kullanıldığı bir ANSI C dili yok C++ dili var
Konunun dagılmasın haz almıyorum..
Isthe console application olarak yarattıgım bir projeden verdiginiz new komutunun cıktısı:
Buyrun...
Dokumanlarında da belirtilidigi gibi ; Visual C++ bir C/C++ compilerdır.
Bu sayede gidip Visual C gibi bir ortam daha edinmenize gerek yoktur.
Euclides
20/04/2004, 17:43
Teşekkür RaiST
Ne için teşekkür ettiğinizi anlamadım.
bu arada sitenizin girişi hoş.
Euclides
20/04/2004, 20:24
Ben bunu böyle yapamıyordum screenshotu gördüm,yanlış bildiğim bir şey doğru ile düzeltim onun için teşekkür ettim
Ok.
Bu arada asıl konuya donus yapsak :)
Euclides
21/04/2004, 17:41
Ewet "Window Handle" dışında bir yöntem daha var ama gene handle'lı :)
socket s;
....
....
....
hEvent=WSACreateEvent();
/* Winsockun kullanabilileceği socket'ten bağımsız event
WSAEventSelect(s,hEvent,FD_READ);
Eğer karşıdan veri aktarınıv talebi gelirse uyar
WSAWaitForMultipleEvents(1,&hEvent,true,WSA_INFINITE,true);
WSAWaitForMultipleEvents(
Beklenecek olay sayısı,
Olayların olduğu yer,
hepsi beklenecek mi?,
ne kadar süre ile beklenecek,
Alertable ??);
....
....
....
long veribuyuk;
ioctlsocket(s,FIONREAD,&veribuyuk);
recv(s,&buf,veribuyuk,0);
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/winsock_functions.asp
evet bunuda biliyordum
WSAEventSelect bunda object handle kullanıyoruz.
yine isime yaramıyor
evet windows bolumu icin cevabı buldum: IOCP (I/O-Completion Ports)
*nix tarafı icin ise IOCP mevcut ama su anda oturmamıs oldugundan bahsediliyor. bu konuyu arastıracagım.
unix tarafında su anda iyi secenek geleneksel nonblocking + signal methodu
proje ilerledikçe daha fazla bilgi vereceğim. bir FAQ yazmaya başladım bile
Euclides
21/04/2004, 23:18
Bunlarda Handle istiyor :)
--------------------------------------------------------------------
I/O Completion Ports
I/O completion ports are the mechanism by which an application uses a pool of threads that was created when the application was started to process asynchronous I/O requests. These threads are created for the sole purpose of processing I/O requests. Applications that process many concurrent asynchronous I/O requests can do so more quickly and efficiently by using I/O completion ports than by using creating threads at the time of the I/O request.
The CreateIoCompletionPort function associates an I/O completion port with one or more file handles. When an asynchronous I/O operation started on a file handle associated with a completion port is completed, an I/O completion packet is queued to the port. This can be used to combine the synchronization point for multiple file handles into a single object.
A thread uses the GetQueuedCompletionStatus function to wait for a completion packet to be queued to the completion port, rather than waiting directly for the asynchronous I/O to complete. Threads that block their execution on a completion port are released in last-in-first-out (LIFO) order. This means that when a completion packet is queued to the completion port, the system releases the last thread to block its execution on the port.
When a thread calls GetQueuedCompletionStatus, it is associated with the specified completion port until it exits, specifies a different completion port, or frees the completion port. A thread can be associated with at most one completion port.
The most important property of a completion port is the concurrency value. The concurrency value of a completion port is specified when the completion port is created. This value limits the number of runnable threads associated with the completion port. When the total number of runnable threads associated with the completion port reaches the concurrency value, the system blocks the execution of any subsequent threads that specify the completion port until the number of runnable threads associated with the completion port drops below the concurrency value. The most efficient scenario occurs when there are completion packets waiting in the queue, but no waits can be satisfied because the port has reached its concurrency limit. In this case, when a running thread calls GetQueuedCompletionStatus, it will immediately pick up the queued completion packet. No context switches will occur, because the running thread is continually picking up completion packets and the other threads are unable to run.
The best value to pick for the concurrency value is the number of CPUs on the computer. If your transaction required a lengthy computation, a larger concurrency value will allow more threads to run. Each transaction will take longer to complete, but more transactions will be processed at the same time. It is easy to experiment with the concurrency value to achieve the best effect for your application.
The PostQueuedCompletionStatus function allows an application to queue its own special-purpose I/O completion packets to the completion port without starting an asynchronous I/O operation. This is useful for notifying worker threads of external events.
The completion port is freed when there are no more references to it. The completion port handle and every file handle associated with the completion port reference the completion port. All the handles must be closed to free the completion port. To close the port handle, call the CloseHandle function.
Evet ; handle istiyor. iyi kodlanmış bir IOCP ile 10000 client handle etmek mumkun..
Ama ben kararımı verdim; cross-platform olmasından dolayı;
nonblocking sockets + tek thread
veya nonblocking sockets + 2<x<10 thread gibi birsey
dusunuyorum. cunki bir MMORPG olarak maksimum 500 kullanıcı bize yeterli
IOCT cok windows ortamında gercekten gerektiginde yararlı. ayrıca linux icinde de IOCT calısmları mevcut..
butun bunları yakında bir FAQ'e ekleyecegim ve bir article base olusturacagım
Euclides
22/04/2004, 14:45
RaiST I/O Comp olayını deneyim dedim AMA bir baktım ki sadece NT :( win9x'lerde yok :(
Evet dogru. Sadece NT sistemler icin mevcut
Forum Yazılımı : vBulletin v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.