From owner-freebsd-hackers Mon Dec 16 18:03:29 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id SAA24539 for hackers-outgoing; Mon, 16 Dec 1996 18:03:29 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id SAA24534 for ; Mon, 16 Dec 1996 18:03:25 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id TAA07421; Mon, 16 Dec 1996 19:01:54 -0700 From: Terry Lambert Message-Id: <199612170201.TAA07421@phaeton.artisoft.com> Subject: Re: Almost have mmap() figured, I think... To: scrappy@hub.org (Marc G. Fournier) Date: Mon, 16 Dec 1996 19:01:54 -0700 (MST) Cc: hackers@freebsd.org In-Reply-To: from "Marc G. Fournier" at Dec 16, 96 08:20:55 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > Altho I really hate to ask, I think I almost have this licked, but > there is something I'm still missing, so the code isn't *quite* working the > way it should. > > Essentially, to simplify things while I "understand it better", > I've created n mmap()'d regions, each representing a frame. There are > n corresponding mmap()'d regions, each of which correspond to the > *size* of the frame. (I know, inelegant, but I can make it more > elegant *after* I know better that which I'm doing...) [ ... ] > The regions are being created as: > > ====== > while(ii < FRAMES) { > sprintf(framestr, "/tmp/frame-%02d", ii); > > /* Setup Video Stream Buffer */ > if((fd = open(framestr, O_RDWR|O_CREAT, 0666)) < 0) { > fprintf(stderr, "cannot open %s\n", framestr); > exit(-1); > } > ftruncate(fd, FRAMESIZE); > if((frame[ii] = > mmap(0, FRAMESIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) > == (caddr_t) -1) { > fprintf(stderr, "cannot mmap frame buffer #%02d\n", ii); > exit(-1); > } > close(fd); > } Alternately: start = mmap( 0, FRAMESIZE * FRAMES, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)); for( i = 0; i < FRAMES; i++) frame[i] = start + i * FRAMESIZE; And use one file... 8-). Also: Are you mapping in both the client and the server? Or just the server? > The problem comes up when I try and print out the frame itself, > using 'printf("%s\n", frame[ii]);'...the value printed out each time > is exactly the same: What is the data in the frame? Maybe that's right? printf("%s", ...) will stop printing if it hit a <00>... > So, I'm making the assumption that either the way I'm calling, or > using, readn() is incorrect for use with mmap()'d regions...would I be > better off to read in the socket, then memcpy() the data, or strncpy()? Or > is what I'm missing even more simple then that? No; reading directly is a win. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.