게임서버/win socket 프로그래밍(10)
-
IOCP 사용중 주의사항
안녕하세요 대학생 개발자입니다. 최근 들어서 거의 2일에 한 번꼴로 글들을 찍어내고 있습니다. 거의 이론위주로 작성을 하고 있는데... 사실 내용이 그렇게 쉬운내용은 아닙니다. 당연히 서버개발을 한다면 이 정도 지식은 함양해야 된다고 생각하지만, 이번 글에서는 잠깐 쉬어가는 느낌으로 IOCP를 사용하면서 주의할 사항이나 문제가 생겼을 때 어떻게 대처할지에 대한 논의를 해보려고 해요. 우선 지난 글에서는 IOCP자체에 대한 내용보다는 Overlapped IO의 시각으로써 IOCP를 사용할 때 주의점을 정리했었습니다. 비동기 IO에 대한 문제점들과 이를 해결하기 위한 방법, 그리고 비동기 IO가 무엇인지에 대한 논의도 했었습니다. 이번 글에서는 IOCP로 에코 서버를 만드는 데 있어서 주의해야 할 점에 대해..
2022.02.19 -
IOCP + Overlapped IO는 비동기IO인가
안녕하세요 대학생 개발자입니다. 저번 글에서는 IOCP에 대한 내용을 정리했습니다. 글에서 핵심 내용만 몇개 뽑아본다면 다음과 같을겁니다. Overlapped IO Model2에서 IO를 타스레드로 전달하기 위한 조건을 걸다보면 결국 IOCP와 거의 흡사한 모습이된다. IOCP를 효율적으로 사용하기 위해 스레드풀을 사용할것이고 스레드풀은 컨텍스트 스위칭과 캐시히트 때문에 스택형태로 되어져있다. CreateIoCompletionPort함수에 파일 핸들과함께 하나의 키값을 등록할 수 있고 그 키는 GQCS함수를 호출할 때 다시 얻을 수 있다.(일반적으로 세션포인터를 전달하고 세션을 달고다니는 셈이된다) Running Thread와 Worker Thread는 우리가 원하는 만큼 세팅할 수 있으며 WorkerT..
2022.02.17 -
IO Completion Port Introduction
안녕하세요 대학생 개발자입니다. 저번 글에서는 Overlapped IO Model2라고 불리는 CALLBACK 방식으로 완료를 통지하는 오버랩 모델에 대해서 논의를 해봤습니다. 이번 글에서는 IOCP에 대한 내용을 다뤄볼 건데요. IOCP는 직전의 글과 같이 동일한 오버랩 모델 중 하나입니다. 먼저 큰 틀에서 말씀을 드린다면 완료 통지를 받는 방법으로 하나의 큐를 통해서 완료 통지를 받고 그 완료 통지를 받았다면 하나의 스레드를 깨워서 작업을 하는 방식을 의미하고 있습니다. 우선 그럼 Overlapped IO Model2에서 IO의 통지를 APC큐를 통해서 했을 경우 문제가 되는 부분은 다음과 같이 말씀드렸습니다. 하나의 APC큐와 IO는 스레드에 종속적이기 때문에 하나의 스레드는 박터져라 일을 하고 있..
2022.02.15 -
Overlapped IO Model2
안녕하세요 대학생 개발자입니다. 저번 글에서는 Overlapped IO Model1에 대한 내용에 대해서 언급했었습니다. Overlapped IO Model1에서는 Event를 이용해서 IO에 대한 완료통지를 하는것이라고 했었고, 그렇기 때문에 생기는 비효율적인 면에 대해서 언급했었습니다. 이번글에서 다룰 내용은 Overlapped IO Model2번째 모델입니다. 아마 이전글에서 언급을 했었겠지만 Overlapped IO Model2의 경우에는 Completion_Routine이라는 CALLBACK 등록을 통해서 IO의 완료 통지를 받는다고 했었습니다. 그럼 우선 우리가 알아야 하는건 CALLBACK이 과연 뭐냐입니다. CALLBACK 많은 사람들이 말을하고 있지만 이게 정확히 뭐냐 라고 물어봤을 때 ..
2022.02.15 -
Overlapped IO Model + heap
안녕하세요 대학생 개발자입니다. 마지막 글에서 동기화에 대한 얘기와 overlapped io모델에 필요한 구조체들에 대한 간단한 언급을 했었습니다. 이번 글에서는 진짜 overlapped io모델에 대한 얘기를 하려고 합니다. 아 그리고 그 이전에 동적 할당과 힙에 대한 잠깐의 논의를 해보고 넘어가려고 합니다. int * ptr = new int[100]; for(int i=0; i< 140; i++) { ptr[i] = 10; } delete ptr; 다음과 같은 코드가 있습니다. 여기서 에러가 나오는 부분은 어디인가라고 물었을 때 대부분의 입문자분들은 ptr[i] = 10; 부분이라고 말할 겁니다. 이렇게 말씀하시는 이유는 알겠으나 일단은 에러가 어디서나냐는 질문에는 틀린 겁니다. Visual Stu..
2022.02.11 -
Overlapped IO Introduction
안녕하세요 대학생개발자입니다. 마지막 글에서 기본적인 소켓 api를 다뤘었습니다. 그리고 한동안 알고리즘과 스레드, 그리고 select 서버에 대한 얘기를 했었습니다. 아마 제가 만든 AsyncSelect 클라이언트를 보셨는지는 모르겠습니다만, 그 이상의 새로운 모델이 아직 나오지 않았었습니다. 그리고 이제 Overlapped IO모델을 정리하면서 동시에 IOCP서버 개발에 착수할 예정입니다. 물론 처음부터 크고 멋진 서버를 만들겠다는 계획은 없습니다. 그리고 스레드 디자인부분도 아직 완벽하지 않기 때문에 확실하게 모든게 짚어지고 나면 그다음 제작에 진입을 할 예정입니다. 우선 서론이 길었습니다. 먼저 이전에 다뤘었던 모델들의 장점과 단점에대한 정리를 간단히 해보고 넘어가도록 하겠습니다. 우선 selec..
2022.02.10 -
L4와 L7그리고 서버
안녕하세요 대학생 개발자입니다. 오늘은 주제가 다양하고 내용이 상당부분 겹치는 부분이있습니다... 내용이 많이 겹칠수도 있으니 이미 이전에 보셨던 분이라면 그 부분은 스킵을 하고 넘어 가셔도 좋을듯 싶습니다. 그럼 시작하겠습니다. 우선 마지막으로 올렸던 글에서는 winsocket api의 가장 기본이 되는 echo server에 나오는 비동기 send recv에 대해서 정리를 해봤습니다. 오늘은 살짝 주제를 바꿔보려고 합니다. 먼저 L2에는 ARP RARP등의 프로토콜이 존재합니다. L3에는 IP, ICMP등의 프로토콜이 존재합니다. L4에는 TCP, UDP등의 프로토콜이 존재합니다. 그들은 각각 자신의 프로토콜과 그에 맞는 syntax와 semantics를 가지고있습니다. 그것들을 가지고 통신을 정의하..
2021.11.04 -
Win socket API2
안녕하세요 대학생 개발자 입니다. 오늘도 역시 winsocket api에 대해서 정리를 해볼까 하는데요... 마지막으로 남겼을때가 listen, accept, bind, socket함수 정도 했었는데요 오늘은... 일단 에코서버의 남은 부분인 recv, send에 대해서 정리를 해볼까 합니다. recv에 대해서 먼저 설명을 해볼까 합니다... 일단 먼저 recv라고 하면 recieve의 줄인말이겠죠 . 받다. 도대체 받는다는게 무엇을 의미하는지 궁금합니다. 우리는 recv를 호출해야지 과연 상대방이 보낸 데이터를 우리의 TCP가 받아들이는 걸까요? 음... 우선 L7과 그 밑을 얘기를 해야겠는데요 먼저 TCP와 소켓은 커널입니다. 커널이라고 하면 우리가 접근할 수 없는 부분인데요... 왜 접근을 못하게 ..
2021.11.03 -
Window Socket API 기본 정리1
안녕하십니까 여러분 대학생 개발자입니다. OSI레이어부터 시작해서 L2 L3 L4까지 차근차근 하나씩 단계를 밟아가면서 정리했습니다. 이제 L5 ~ L7이라고 불릴 수 있는 어플리케이션 레이어에서의 네트워크를 정리하려고 합니다. msdn을 조금씩 참고해서 적긴하는데... msdn에 있는 문서나 사진을 올리진 않습니다... 제 머릿속에 있는 내용을 최대한 끄집어 내려고 하기 때문이니까... 이해 부탁드립니다. 음... 순서도 그렇고 내용도 그렇고 뒤죽박죽일겁니다... 하지만 이 블로깅에 목적은 역시 제가 나중에 다시 보고 공부하기 위해서 남기는 목적이다보니... 이런 배려는 없다는점 유의하시길 바랍니다 ㅋㅋㅋㅋㅋ 추가로 여기에 올라오는것중 많은 부분이 생략이 되어있을 겁니다. 그건... 다른 블로그나 다른..
2021.11.01 -
Windows 에서 listen함수의 Backlog Queue의 크기를 구해보자.
안녕하세요 대학생 개발자입니다. 오늘의 목표는 listen을 했을 때 커널에 back log queue(listen queue)가 생기는데 그 큐의 사이즈의 크기를 코드로 직접 구해보려고 합니다. 서버 측에서 listen을 콜 할 때 SOMAXCONN -> 7fffffff signed int 중 가장 큰 값을 인자로 전달합니다. client에서 실제 connect를 과연 몇 개까지 할 수 있을까를 실험해봤습니다. client는 무한루프를 돌면서 loop back address:8000 으로 connect를 시도합니다. 실제 연결된 클라이언트 수는 200명에 불과합니다. 분명 나는 signed int 중 가장 큰 값인 7fffffff를 인자로 전달했는데 왜 200개밖에 되지 않을까? 당연히 21억어쩌고하는..
2021.10.27