질문2개: '파이프가 깨짐' + 'Timer (in Single process program

indizarm의 이미지

상황 1. 서버 프로세스 1개가 떠 있고, 똑같은 클라이언트가 n개 서버에
_____접속해 있습니다. (blocking socket, TCP, select() 형태의 서버)
_____이중에 클라이언트 i (i <=n) 에서 'Ctrl + c/ z'등으로 '비정상적'인
_____종료를 하면 서버와 나머지 클라이언트들이 모두 '파이프가 깨짐'
_____이렇게 종료되는군요.

물음 1. 왜 이럴까요? (-_-;; 소켓때문에 문제가 발생하는 것 같기는 한데...)
물음 1.1 어떻게 해야 처치할 수 있을까요?

상황 2. Single process 만으로 온갖 삽질을 하는 프로그램이 있습니다.
원하는 것 2. 작업 a를 수행하고서 일정시간 응답이 없으면, 다시 시도하려
_________합니다.

물음 2. 어떻게 해야 시간을 check할 수 있을까요?
______(Single process, 작업 a는 'block'되는 성격의 작업) => 제 개인적으
__________________________________________로는 불가능하지
__________________________________________않을까라고 생각
______(CALLBACK 함수같은 것을 등록할 수 있을까요?
______등록하더라도 어떻게 알고서 처리할 수 있을까요?
______또는 어떻게 처리해야 할까요? 예를 들어서 loop에서
______여러개의 flag를 만들어서 체크하면서 '복잡스런' 작업을
______해야할까요? '초난감' 입니다요. '무서운 쿰을 쿠얶꾸나~' -_-;;)

stoneshim의 이미지

상황1. SIGPIPE를 ignore 하도록 sigaction 을 사용하시면 될듯 합니다.

client의 socket이 close되어 FIN이 날라오면 select에서 readable 하다고 리턴하게 되고 read()가 0를 리턴하여 peer가 소켓을 close했음을 알아차리는것이 순서이나, 서버가 client에 write 할 때, 혹은 하기 직전의 상황이라면 select()에서 기다리고 있는 상황이 아니므로, write시에 SIGPIPE가 발생합니다.

SIGPIPE를 ignore 하시고, write() 시에 -1 return이고 errno가 EPIPE인 경우에 대해 처리 해주시면 될듯 합니다.

Quote:
상황 2. Single process 만으로 온갖 삽질을 하는 프로그램이 있습니다.
원하는 것 2. 작업 a를 수행하고서 일정시간 응답이 없으면, 다시 시도하려
_________합니다.

'일정시간 응답이 없으면' 에서 응답은 누가 해주는 건지... 정확히 상황을 이해하지 못하겠네요.
일단 multi-thread환경이 아니라면, alarm을 사용하면 안되나요?

우리 모두 리얼리스트가 되자. 그러나 가슴에 이룰 수 없는 꿈을 가지자

indizarm의 이미지

(클라이언트나 서버 등 )상대방에서 응답이 없으면 이라는
의미였습니다.

지금 말씀해주신, SIGPIPE와 alarm에 대해서 찾아보고 있습
니다. 답변 감사합니다. ^_^

What a Cool Days!!!

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.