feat: first server only implements error
This commit is contained in:
parent
789edbd338
commit
48c95a8370
1 changed files with 49 additions and 0 deletions
49
server.scm
Normal file
49
server.scm
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
;; Basic Gemini server
|
||||||
|
;;
|
||||||
|
;; Copyright (C) 2022 rick G. <rick@gnous.eu>
|
||||||
|
;;
|
||||||
|
;; This program is free software: you can redistribute it and/or modify it under
|
||||||
|
;; the terms of the GNU General Public License as published by the Free Software
|
||||||
|
;; Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
;; version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License along with
|
||||||
|
;; this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
;;( use-modules (gnutls) )
|
||||||
|
(use-modules (ice-9 binary-ports) (ice-9 iconv) (rnrs bytevectors))
|
||||||
|
|
||||||
|
(define chaussette (socket PF_INET SOCK_STREAM 0))
|
||||||
|
(bind chaussette AF_INET INADDR_ANY 8082)
|
||||||
|
(listen chaussette 1)
|
||||||
|
(display "Chaussette en place")
|
||||||
|
(newline)
|
||||||
|
(while #t
|
||||||
|
(let (( rep (accept chaussette )))
|
||||||
|
(let ((out (car rep)) (in (cdr rep)))
|
||||||
|
(define text (make-bytevector 1024))
|
||||||
|
(define pos #f)
|
||||||
|
(recvfrom! out text)
|
||||||
|
|
||||||
|
(set! pos (string-contains (bytevector->string text "UTF-8")
|
||||||
|
(string #\return #\nl)))
|
||||||
|
|
||||||
|
;; si ya pas de \cr\nl, buffer trop grand ou mal formaté
|
||||||
|
(when (not pos) (begin
|
||||||
|
(display (string-append "59 Bad Request" (string #\return #\nl)) out))
|
||||||
|
)
|
||||||
|
|
||||||
|
(unless (not pos) (begin
|
||||||
|
(display "all ok")
|
||||||
|
))
|
||||||
|
|
||||||
|
(shutdown out 2)
|
||||||
|
)))
|
||||||
|
|
||||||
|
(close chaussette)
|
||||||
|
(display "Atterissage réussi")
|
||||||
|
(newline)
|
Loading…
Reference in a new issue