comparison tcp.c @ 1787:eb16c64144ee libavformat

This fixes error handling for BeOS, removing the need for some ifdefs. AVERROR_ defines are moved to avcodec.h as they are needed in there as well. Feel free to move that to avutil/common.h. Bumped up avcodec/format version numbers as though it's binary compatible we will want to rebuild apps as error values changed. Please from now on use return AVERROR(EFOO) instead of the ugly return -EFOO in your code. This also removes the need for berrno.h.
author mmu_man
date Tue, 13 Feb 2007 18:26:14 +0000
parents 1f7a6dc01100
children d85795da84ab
comparison
equal deleted inserted replaced
1786:8cc34fe98a3b 1787:eb16c64144ee
60 if (strcmp(proto,"tcp")) goto fail; // PETR: check protocol 60 if (strcmp(proto,"tcp")) goto fail; // PETR: check protocol
61 if ((q = strchr(hostname,'@'))) { strcpy(tmp,q+1); strcpy(hostname,tmp); } // PETR: take only the part after '@' for tcp protocol 61 if ((q = strchr(hostname,'@'))) { strcpy(tmp,q+1); strcpy(hostname,tmp); } // PETR: take only the part after '@' for tcp protocol
62 62
63 s = av_malloc(sizeof(TCPContext)); 63 s = av_malloc(sizeof(TCPContext));
64 if (!s) 64 if (!s)
65 return -ENOMEM; 65 return AVERROR(ENOMEM);
66 h->priv_data = s; 66 h->priv_data = s;
67 67
68 if (port <= 0 || port >= 65536) 68 if (port <= 0 || port >= 65536)
69 goto fail; 69 goto fail;
70 70
88 goto fail; 88 goto fail;
89 89
90 /* wait until we are connected or until abort */ 90 /* wait until we are connected or until abort */
91 for(;;) { 91 for(;;) {
92 if (url_interrupt_cb()) { 92 if (url_interrupt_cb()) {
93 ret = -EINTR; 93 ret = AVERROR(EINTR);
94 goto fail1; 94 goto fail1;
95 } 95 }
96 fd_max = fd; 96 fd_max = fd;
97 FD_ZERO(&wfds); 97 FD_ZERO(&wfds);
98 FD_SET(fd, &wfds); 98 FD_SET(fd, &wfds);
128 fd_set rfds; 128 fd_set rfds;
129 struct timeval tv; 129 struct timeval tv;
130 130
131 for (;;) { 131 for (;;) {
132 if (url_interrupt_cb()) 132 if (url_interrupt_cb())
133 return -EINTR; 133 return AVERROR(EINTR);
134 fd_max = s->fd; 134 fd_max = s->fd;
135 FD_ZERO(&rfds); 135 FD_ZERO(&rfds);
136 FD_SET(s->fd, &rfds); 136 FD_SET(s->fd, &rfds);
137 tv.tv_sec = 0; 137 tv.tv_sec = 0;
138 tv.tv_usec = 100 * 1000; 138 tv.tv_usec = 100 * 1000;
139 ret = select(fd_max + 1, &rfds, NULL, NULL, &tv); 139 ret = select(fd_max + 1, &rfds, NULL, NULL, &tv);
140 if (ret > 0 && FD_ISSET(s->fd, &rfds)) { 140 if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
141 len = recv(s->fd, buf, size, 0); 141 len = recv(s->fd, buf, size, 0);
142 if (len < 0) { 142 if (len < 0) {
143 if (errno != EINTR && errno != EAGAIN) 143 if (errno != EINTR && errno != EAGAIN)
144 #ifdef __BEOS__ 144 return AVERROR(errno);
145 return errno;
146 #else
147 return -errno;
148 #endif
149 } else return len; 145 } else return len;
150 } else if (ret < 0) { 146 } else if (ret < 0) {
151 return -1; 147 return -1;
152 } 148 }
153 } 149 }
161 struct timeval tv; 157 struct timeval tv;
162 158
163 size1 = size; 159 size1 = size;
164 while (size > 0) { 160 while (size > 0) {
165 if (url_interrupt_cb()) 161 if (url_interrupt_cb())
166 return -EINTR; 162 return AVERROR(EINTR);
167 fd_max = s->fd; 163 fd_max = s->fd;
168 FD_ZERO(&wfds); 164 FD_ZERO(&wfds);
169 FD_SET(s->fd, &wfds); 165 FD_SET(s->fd, &wfds);
170 tv.tv_sec = 0; 166 tv.tv_sec = 0;
171 tv.tv_usec = 100 * 1000; 167 tv.tv_usec = 100 * 1000;
172 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv); 168 ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
173 if (ret > 0 && FD_ISSET(s->fd, &wfds)) { 169 if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
174 len = send(s->fd, buf, size, 0); 170 len = send(s->fd, buf, size, 0);
175 if (len < 0) { 171 if (len < 0) {
176 if (errno != EINTR && errno != EAGAIN) { 172 if (errno != EINTR && errno != EAGAIN)
177 #ifdef __BEOS__ 173 return AVERROR(errno);
178 return errno;
179 #else
180 return -errno;
181 #endif
182 }
183 continue; 174 continue;
184 } 175 }
185 size -= len; 176 size -= len;
186 buf += len; 177 buf += len;
187 } else if (ret < 0) { 178 } else if (ret < 0) {