~linaro-maintainers/ubuntu/maverick/qemu-linaro/ppa

« back to all changes in this revision

Viewing changes to osdep.c

  • Committer: Steve Langasek
  • Date: 2012-02-07 21:16:06 UTC
  • mfrom: (12827.2.30 trunk)
  • Revision ID: steve.langasek@canonical.com-20120207211606-mg6clflsfvz9f74x
Tags: 1.0.50-2012.01-0ubuntu2~ppa10.10.1
upload to the tools ppa

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include "trace.h"
49
49
#include "qemu_socket.h"
50
50
 
 
51
int socket_set_cork(int fd, int v)
 
52
{
 
53
#if defined(SOL_TCP) && defined(TCP_CORK)
 
54
    return setsockopt(fd, SOL_TCP, TCP_CORK, &v, sizeof(v));
 
55
#else
 
56
    return 0;
 
57
#endif
 
58
}
 
59
 
51
60
int qemu_madvise(void *addr, size_t len, int advice)
52
61
{
53
62
    if (advice == QEMU_MADV_INVALID) {
166
175
 
167
176
    return ret;
168
177
}
 
178
 
 
179
/*
 
180
 * A variant of send(2) which handles partial write.
 
181
 *
 
182
 * Return the number of bytes transferred, which is only
 
183
 * smaller than `count' if there is an error.
 
184
 *
 
185
 * This function won't work with non-blocking fd's.
 
186
 * Any of the possibilities with non-bloking fd's is bad:
 
187
 *   - return a short write (then name is wrong)
 
188
 *   - busy wait adding (errno == EAGAIN) to the loop
 
189
 */
 
190
ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags)
 
191
{
 
192
    ssize_t ret = 0;
 
193
    ssize_t total = 0;
 
194
 
 
195
    while (count) {
 
196
        ret = send(fd, buf, count, flags);
 
197
        if (ret < 0) {
 
198
            if (errno == EINTR) {
 
199
                continue;
 
200
            }
 
201
            break;
 
202
        }
 
203
 
 
204
        count -= ret;
 
205
        buf += ret;
 
206
        total += ret;
 
207
    }
 
208
 
 
209
    return total;
 
210
}
 
211
 
 
212
/*
 
213
 * A variant of recv(2) which handles partial write.
 
214
 *
 
215
 * Return the number of bytes transferred, which is only
 
216
 * smaller than `count' if there is an error.
 
217
 *
 
218
 * This function won't work with non-blocking fd's.
 
219
 * Any of the possibilities with non-bloking fd's is bad:
 
220
 *   - return a short write (then name is wrong)
 
221
 *   - busy wait adding (errno == EAGAIN) to the loop
 
222
 */
 
223
ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags)
 
224
{
 
225
    ssize_t ret = 0;
 
226
    ssize_t total = 0;
 
227
 
 
228
    while (count) {
 
229
        ret = qemu_recv(fd, buf, count, flags);
 
230
        if (ret <= 0) {
 
231
            if (ret < 0 && errno == EINTR) {
 
232
                continue;
 
233
            }
 
234
            break;
 
235
        }
 
236
 
 
237
        count -= ret;
 
238
        buf += ret;
 
239
        total += ret;
 
240
    }
 
241
 
 
242
    return total;
 
243
}
 
244