summaryrefslogtreecommitdiffstats
path: root/stream/stream_smb.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-12 22:07:07 +0200
committerwm4 <wm4@nowhere>2013-07-12 22:16:26 +0200
commitf63193f58f7214ef3a4f82be045f8a3cfd14b8ac (patch)
tree77bc53b7125730af961fb8b9298ef00f128d6576 /stream/stream_smb.c
parentb66c609b4826059d348f6e1c049a34cc43415383 (diff)
downloadmpv-f63193f58f7214ef3a4f82be045f8a3cfd14b8ac.tar.bz2
mpv-f63193f58f7214ef3a4f82be045f8a3cfd14b8ac.tar.xz
stream: remove fd member
Stream implementations could set this to a unix file descriptor. The generic stream code could use it as fallback for a few things. This was confusing and insane. In most cases, the stream implementations defined all callbacks, so setting the fd member didn't have any advantages, other than avoiding defining a private struct to store it. It appears that even if the stream implementation used close() on the fd (or something equivalent), stream.c would close() it a second time (and on windows, even would call closesocket()), which should be proof for the insanity of this code. For stream_file.c, additionally make sure we don't close stdin or stdout if "-" is used as filename. For stream_vcd.c, remove the control() code. This code most likely didn't make the slightest sense, because it used a different type for stream->priv. It also leaked memory. Maybe it worked, but it's incorrect and insignificant anyway, so kill it. This code was added with commit 9521c19 (svn commit 31019). Untested for all protocols other than stream_file.c.
Diffstat (limited to 'stream/stream_smb.c')
-rw-r--r--stream/stream_smb.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/stream/stream_smb.c b/stream/stream_smb.c
index d98d3485c1..5c9a4a6b0b 100644
--- a/stream/stream_smb.c
+++ b/stream/stream_smb.c
@@ -26,6 +26,10 @@
#include "core/m_option.h"
#include "core/m_struct.h"
+struct priv {
+ int fd;
+};
+
static struct stream_priv_s {
} stream_priv_dflts = {
};
@@ -72,10 +76,11 @@ static void smb_auth_fn(const char *server, const char *share,
}
static int control(stream_t *s, int cmd, void *arg) {
+ struct priv *p = s->priv;
switch(cmd) {
case STREAM_CTRL_GET_SIZE: {
- off_t size = smbc_lseek(s->fd,0,SEEK_END);
- smbc_lseek(s->fd,s->pos,SEEK_SET);
+ off_t size = smbc_lseek(p->fd,0,SEEK_END);
+ smbc_lseek(p->fd,s->pos,SEEK_SET);
if(size != (off_t)-1) {
*(uint64_t *)arg = size;
return 1;
@@ -86,23 +91,26 @@ static int control(stream_t *s, int cmd, void *arg) {
}
static int seek(stream_t *s,int64_t newpos) {
+ struct priv *p = s->priv;
s->pos = newpos;
- if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) {
+ if(smbc_lseek(p->fd,s->pos,SEEK_SET)<0) {
return 0;
}
return 1;
}
static int fill_buffer(stream_t *s, char* buffer, int max_len){
- int r = smbc_read(s->fd,buffer,max_len);
+ struct priv *p = s->priv;
+ int r = smbc_read(p->fd,buffer,max_len);
return (r <= 0) ? -1 : r;
}
static int write_buffer(stream_t *s, char* buffer, int len) {
+ struct priv *p = s->priv;
int r;
int wr = 0;
while (wr < len) {
- r = smbc_write(s->fd,buffer,len);
+ r = smbc_write(p->fd,buffer,len);
if (r <= 0)
return -1;
wr += r;
@@ -112,7 +120,8 @@ static int write_buffer(stream_t *s, char* buffer, int len) {
}
static void close_f(stream_t *s){
- smbc_close(s->fd);
+ struct priv *p = s->priv;
+ smbc_close(p->fd);
}
static int open_f (stream_t *stream, int mode, void *opts)
@@ -122,6 +131,9 @@ static int open_f (stream_t *stream, int mode, void *opts)
int64_t len;
int fd, err;
+ struct priv *priv = talloc_zero(stream, struct priv);
+ stream->priv = priv;
+
filename = stream->url;
if(mode == STREAM_READ)
@@ -165,7 +177,7 @@ static int open_f (stream_t *stream, int mode, void *opts)
stream->seek = seek;
if(mode == STREAM_READ) stream->end_pos = len;
}
- stream->fd = fd;
+ priv->fd = fd;
stream->fill_buffer = fill_buffer;
stream->write_buffer = write_buffer;
stream->close = close_f;