File: file-socket.lisp

package info (click to toggle)
cl-uffi 1.5.17-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 732 kB
  • ctags: 389
  • sloc: lisp: 3,496; xml: 2,979; makefile: 249; ansic: 169; sh: 82
file content (39 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name:          file-socket.cl
;;;; Purpose:       UFFI Example file to get a socket on a file
;;;; Programmer:    Kevin M. Rosenberg
;;;; Date Started:  Jul 2002
;;;;
;;;; $Id: file-socket.lisp 10608 2005-07-01 00:39:48Z kevin $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg
;;;;
;;;; *************************************************************************

(in-package :cl-user)

;; Values for linux
(uffi:def-constant PF_UNIX 1)
(uffi:def-constant SOCK_STREAM 1)

(uffi:def-function ("socket" c-socket)
    ((family :int)
     (type :int)
     (protocol :int))
    :returning :int)

(uffi:def-function ("connect" c-connect)
    ((sockfd :int)
     (serv-addr :void-pointer)
     (addr-len :int))
    :returning :int)
		  
(defun connect-to-file-socket (filename)
  (let ((socket (c-socket PF_UNIX SOCK_STREAM 0)))
    (if (plusp socket)
	(let ((stream (c-connect socket filename (length filename))))
	  stream)
      (error "Unable to create socket"))))