Re: question - php_stream_cast(...) and PHP_STREAM_AS_FD
| From: | Wez Furlong | Date: | Mon, 09 Feb 2004 15:44:09 +0000 |
| Subject: | Re: question - php_stream_cast(...) and PHP_STREAM_AS_FD | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-410@lists.php.net to get a copy of this message | ||
If you're writing to a stream, you shouldn't use STREAM_MUST_SEEK, since
it might give you a temporary stream that is not connected to the actual
resource you
opened; such a stream will be deleted when it is closed.
Generally speaking, you should avoid using casting when possible; can you
give
more details about what you're opening (remote files?). Also, it looks like
you
are nesting streams--can I ask why? (it might be possible to do things a bit
more
cleanly).
--Wez.
PS: I hope you found this:
http://uk.php.net/manual/en/streams.php
----- Original Message -----
From: "Justin Hannus" <jhannus@visualconceptsinc.com>
To: <pecl-dev@lists.php.net>
Sent: Monday, February 09, 2004 3:25 PM
Subject: [PECL-DEV] question - php_stream_cast(...) and PHP_STREAM_AS_FD
> I'm trying to open a php stream and cast it as an fd so I can use it with
a
> third party library that expects an fd to read from sound files. This is
all
> fine and well for read mode but when I try to open the file in write mode,
> it opens it in read instead. I'm fully aware that the stream must be
opened
> in the same mode as I'm opening the file with (the fd) but I'm not sure if
I
> have the cast correct. Heres a snippet:
>
> // ... from php_stream * php_stream_sf_open(...
> // ...
> self = (struct php_sf_stream_data_t *) emalloc(sizeof(*self));
> innerstream = php_stream_open_wrapper(path, mode, STREAM_MUST_SEEK |
> options | STREAM_WILL_CAST, opened_path);
>
> if (innerstream) {
> self->mode = strchr(mode, 'r') ? SFM_READ : SFM_WRITE;
>
> if (php_stream_cast(innerstream, PHP_STREAM_AS_FD |
> PHP_STREAM_CAST_RELEASE, (void **) &self->fd, REPORT_ERRORS) == SUCCESS) {
> self->sf = sf_open_fd(self->fd, self->mode, &self->sfinfo,
> SF_TRUE);
>
> // ... more stuff
>
>
> Works fine for me when opened in read mode but also opens in read when I
> specify write. Do I have the cast written correctly?
>
> --
> Justin Hannus
> Lead Programmer/Web Development
> jhannus@visualconceptsinc.com
> www.visualconceptsinc.com
> [860] 242.1150 ext.125
> [860] 242.1446 fax
>
> --
> PECL development discussion Mailing List (http://pecl.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>