TCP/IP 소켓 통신에서 시그널에 대한 질문입니다.

anaud2의 이미지

안녕하세요

TCP/IP 소켓 통신에서 SIGALARM 시그널 핸들러를 사용해서 전송중이나 커넥션을 맺을때 무한 대기상태를
빠지는것을 막고 있습니다.

유닉스나 리눅스에서는 전혀 문제가 없지만 윈도우로 포팅하는 부분에서 문제가 생겼습니다.

/* timeout 설정 */
struct sigaction sigact, oldact;
sigact.sa_handler = sig_handler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigact.sa_flags |= SA_INTERRUPT;

timeout을 설정하는 부분에서 sigaction 구조체를 전혀 못찾고 있습니다.
윈도우에서는 signal 핸들러를 사용할수 없는것인가요? 아니면 다른 헤더파일이 있는것인가요

책에서 SIGALARM의 정의도 아래와 같은데
#include
unsigned int alarm(unsigned int soconds)

윈도우에서는 unistd.h 의 헤더파일이 없더라구요...

음..책에서는 윈도우에서 처리방안을 안써놨던데 ...어케 해야되는건가요...
예전에 sigalarm을 쓸때도 select를 쓰란말을 많이 듣긴했지만 모르는 부눈이라서 시간이 없어서
그거 공부해서 구현하기가 힘드네요 ㅠㅠ 도와주세요~

Necromancer의 이미지

윈도우는 유닉스스타일의 시그널 지원 안합니다.

간단하게 timeout을 검출할려면 timeout 검출용과 통신용 스레드로 나누어서
timeout 스레드로 검출하면 되고,

깔끔하게 끝내려면 비동기 입출력을 사용하는게 좋습니다.

Written By the Black Knight of Destruction

Written By the Black Knight of Destruction

anaud2의 이미지

비동기 방식 보다 간단하게 timeout을 검출하는 방식을 택하고 싶은데요
답변을 주신것중에 이해가 안되는부분이 timeout검용과 통신용 스레드를 나누어서 timeout스레드로 검출한다는게...이해가 좀 안되는데요 좀더 자세히 설명 해주시면 감사하겠습니다.

Necromancer의 이미지

스레드 나눈 뒤 한넘은 통신작업을 수행하고, 한넘은 일정시간 동안 잠듭니다.
잠든 넘이 깨어날때 통신하는 넘이 connect 등에서 블럭 걸려있는것을 확인해서 걸려있다면 그 스레드 죽이는거죠.

그런데 스레드 강제로 죽이는 거는 별로 추천 안합니다.

Written By the Black Knight of Destruction

Written By the Black Knight of Destruction

pizza1977의 이미지

비동기나 non-blocking 소켓에 대한 학습이
그리 어려울것 같지는 않습니다만...

아시다시피 시스템 프로그램쪽에 가까워 질수록
이기종 포팅에 대한 제약이 심해집니다.

머 시그날이나 소켓이나 거기서 거기지만...

시그날을 그정도 활용할 능력이면 Socket의 비동기 버전은
잘 이해하실 것 같네요.

머 네트웍 하루 하고 안하실거면 몰라도 비동기, non-blocking
Socket은 선택이 아닌 필수입니다.

-------------
포탈이는 불사신

-------------
포탈이는 불사신

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.