unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Amirouche Boubekki <amirouche@hypermove.net>
To: 23000@debbugs.gnu.org
Subject: bug#23000: send doesn't check for closed socket
Date: Sat, 12 Mar 2016 19:57:35 +0100	[thread overview]
Message-ID: <0c47cb865118629de2217d50490346d0@hypermove.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 273 bytes --]

The attached client.scm will crash with a SIGPIPE (based on strace) when 
run. It should raise an error instead.

The error happens when we try to send over socket that is closed on the 
other side.

Happens on 2.0 and master.

-- 
Amirouche ~ amz3 ~ http://www.hyperdev.fr

[-- Attachment #2: client.scm --]
[-- Type: text/plain, Size: 377 bytes --]

(define-module (client))

(use-modules (shared))

(define (client)
  (define socket (make-client-socket 12348))
  (pk (send socket (list->u64vector (iota 3))))
  (pk (recv socket))
  (pk "sleeping")
  (sleep 15)
  (pk (send socket (list->u64vector (iota 3))))
  (pk (send socket (list->u64vector (iota 3))))
  (pk (close socket))
  (pk "bye"))


(client)
(pk "end of program")

[-- Attachment #3: shared.scm --]
[-- Type: text/plain, Size: 681 bytes --]

(define-module (shared))

(use-modules (rnrs io ports))

(define-public (recv port)
  (let next ((out '()))
    (if (char-ready? port)
        (let ((byte (get-u8 port)))
          (if (eof-object? byte)
              (reverse out)
              (next (cons byte out))))
        (reverse out))))

(define make-socket socket)

(define-public (make-client-socket port)
  (let ((socket (make-socket PF_INET SOCK_STREAM 0)))
    (connect socket AF_INET INADDR_LOOPBACK port)
    socket))

(define-public (make-server-socket port)
  (let ((socket (make-socket PF_INET SOCK_STREAM 0)))
    (bind socket (make-socket-address AF_INET INADDR_ANY port))
    (listen socket 128)
    socket))

[-- Attachment #4: server.scm --]
[-- Type: text/plain, Size: 220 bytes --]

(define-module (server))

(use-modules (shared))

(define (server)
  (let* ((sock (make-server-socket 12348))
         (client (car (accept sock))))
    (pk (recv client))
    (close client)
    (close sock)))

(server)

             reply	other threads:[~2016-03-12 18:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-12 18:57 Amirouche Boubekki [this message]
2016-05-03  9:07 ` bug#23000: update from wingo Amirouche Boubekki
2016-06-20 16:18   ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c47cb865118629de2217d50490346d0@hypermove.net \
    --to=amirouche@hypermove.net \
    --cc=23000@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).