On 29/11/11 10:53, Martin Storsjö wrote:
Same comment as in the previous iteration:
Hmm, is this common practice for unix socket addresses? Shouldn't a
plain sizeof(s->addr) work too, since the string is contained within
that anyway?
I'm not saying it's wrong, I just want a comment on it.
Forgot to reply sorry, it seems to be a common practice, I hadn't
checked the libc/linux code to see if it would make any difference.
+
+ fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+
+ if (fd < 0) {
+ av_free(s);
+ return AVERROR(ENOMEM);
+ }
+
+ if (flags & URL_WRONLY)
+ ret = connect(fd, (struct sockaddr *)&s->addr, s->addr_len);
+ else
+ ret = bind(fd, (struct sockaddr *)&s->addr, s->addr_len);
+
+ if (ret < 0) {
+ av_free(s);
+ closesocket(fd);
+ return AVERROR(EIO);
+ }
These error returns could perhaps still be combined into a goto fail
path for simplification. And if the priv_data is allocated by the caller
(by setting priv_data_size), one wouldn't have to take care of
freeing/allocating that here either. But this is just extra, the code is
correct and ok this way of course.
You are right.
+
+ ff_socket_nonblock(fd, 1);
+
+ h->priv_data = s;
+ h->is_streamed = 1;
+ s->fd = fd;
+
+ return 0;
+}
+
+static int unix_wait_fd(int fd, int write)
+{
+ int ev = write ? POLLOUT : POLLIN;
+ struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
+ int ret;
+
+ ret = poll(&p, 1, 100);
+ return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN);
+}
+
+static int unix_read(URLContext *h, uint8_t *buf, int size)
+{
+ UnixContext *s = h->priv_data;
+ int ret;
+
+ if (!(h->flags & URL_FLAG_NONBLOCK)) {
+ ret = unix_wait_fd(s->fd, 0);
+ if (ret < 0)
+ return ret;
+ }
+ ret = recv(s->fd, buf, size, 0);
+ return ret < 0 ? ff_neterrno() : ret;
+}
+
+static int unix_write(URLContext *h, const uint8_t *buf, int size)
+{
+ UnixContext *s = h->priv_data;
+ int ret;
+
+ if (!(h->flags & URL_FLAG_NONBLOCK)) {
+ ret = unix_wait_fd(s->fd, 1);
+ if (ret < 0)
+ return ret;
+ }
+ ret = send(s->fd, buf, size, 0);
+ return ret < 0 ? ff_neterrno() : ret;
+}
+
+static int unix_close(URLContext *h)
+{
+ UnixContext *s = h->priv_data;
+ closesocket(s->fd);
+ if (h->flags & URL_RDONLY)
+ unlink(s->addr.sun_path);
Same as for the other unix socket thing, I'd like to know why this is
done (please explain the normal usage pattern).
you create the file on the listening side and you have to unlink it,
again it is a common =)
An update will follow soon =)
--
Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel