~ubuntu-branches/ubuntu/breezy/orbit2/breezy

« back to all changes in this revision

Viewing changes to src/orb/GIOP/giop-send-buffer.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-09-06 16:37:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050906163702-hrqi0ctymth53bnn
Tags: 1:2.12.4-0ubuntu1
* New upstream version.
* debian/patches/100-compile-name-server.patch:
  - updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <string.h>
3
3
#include <sys/types.h>
4
4
#include "giop-private.h"
5
 
#include <sys/uio.h>
 
5
#ifdef HAVE_SYS_UIO_H
 
6
#  include <sys/uio.h>
 
7
#endif
6
8
#include <orbit/GIOP/giop.h>
7
9
#include "../util/orbit-purify.h"
8
10
 
9
11
#define GIOP_CHUNK_ALIGN 8
10
12
#define GIOP_CHUNK_SIZE (GIOP_CHUNK_ALIGN * 256)
11
13
 
 
14
static gboolean giop_blank_wire_data = FALSE;
12
15
static GSList *send_buffer_list = NULL;
13
16
static GMutex *send_buffer_list_lock = NULL;
14
17
 
15
18
static const char giop_zero_buf [GIOP_CHUNK_ALIGN * 10] = {0};
16
19
 
17
20
void
18
 
giop_send_buffer_init (void)
 
21
giop_send_buffer_init (gboolean wipe)
19
22
{
20
 
        send_buffer_list_lock = linc_mutex_new ();
 
23
#ifdef ORBIT_PURIFY
 
24
        giop_blank_wire_data = TRUE;
 
25
#else
 
26
        giop_blank_wire_data = wipe;
 
27
#endif
 
28
        send_buffer_list_lock = link_mutex_new ();
21
29
}
22
30
 
23
31
/* Marshal it at compile time so we don't have to do it over and over. This just stores codeset info to say that
45
53
                              const struct iovec *operation_vec,
46
54
                              const struct iovec *principal_vec)
47
55
{
48
 
  GIOPSendBuffer *buf = giop_send_buffer_use(giop_version);
49
 
  struct iovec zerovec;
50
 
 
51
 
  if(!principal_vec)
52
 
    {
53
 
      zerovec.iov_base = (gpointer) giop_zero_buf;
54
 
      zerovec.iov_len = sizeof(CORBA_unsigned_long);
55
 
      principal_vec = &zerovec;
56
 
    }
57
 
 
58
 
  buf->msg.header.message_type = GIOP_REQUEST;
59
 
  giop_send_buffer_align(buf, sizeof(CORBA_unsigned_long));
60
 
  buf->msg.u.request_1_0.request_id = request_id;
61
 
  buf->msg.u.request_1_0.response_expected = response_expected;
62
 
 
63
 
  switch(giop_version)
64
 
    {
65
 
    case GIOP_1_0:
66
 
    case GIOP_1_1:
67
 
      giop_send_buffer_append(buf, (const guchar *)iop_service_context_data, sizeof(iop_service_context_data));
68
 
      giop_send_buffer_append(buf, &buf->msg.u.request_1_0.request_id, sizeof(CORBA_unsigned_long));
69
 
      giop_send_buffer_append(buf, &buf->msg.u.request_1_0.response_expected, sizeof(CORBA_boolean));
70
 
      giop_send_buffer_append_aligned(buf, &objkey->_length, sizeof(CORBA_unsigned_long));
71
 
      giop_send_buffer_append(buf, objkey->_buffer, objkey->_length);
72
 
      giop_send_buffer_align(buf, sizeof(CORBA_unsigned_long));
73
 
      giop_send_buffer_append(buf, operation_vec->iov_base, operation_vec->iov_len);
74
 
      giop_send_buffer_append(buf, principal_vec->iov_base, principal_vec->iov_len);
75
 
      break;
76
 
    case GIOP_1_2:
77
 
      giop_send_buffer_align(buf, sizeof(CORBA_unsigned_long));
78
 
      giop_send_buffer_append(buf, &buf->msg.u.request_1_0.request_id, sizeof(CORBA_unsigned_long));
79
 
      giop_send_buffer_append(buf, &buf->msg.u.request_1_0.response_expected, sizeof(CORBA_boolean));
80
 
      giop_send_buffer_append(buf, giop_zero_buf, 3);
81
 
      giop_send_buffer_append(buf, &giop_1_2_target_type, 2); /* We always use GIOP::KeyAddr addressing - the only sane way */
82
 
      giop_send_buffer_append_aligned(buf, &objkey->_length, sizeof(CORBA_unsigned_long));
83
 
      giop_send_buffer_append(buf, objkey->_buffer, objkey->_length);
84
 
      giop_send_buffer_align(buf, sizeof(CORBA_unsigned_long));
85
 
      giop_send_buffer_append(buf, operation_vec->iov_base, operation_vec->iov_len);
86
 
      giop_send_buffer_append(buf, (const guchar *)iop_service_context_data, sizeof(iop_service_context_data));
87
 
      giop_send_buffer_align(buf, 8); /* alignment for the body */
88
 
    default:
89
 
      break;
90
 
    }
91
 
 
92
 
  return buf;
 
56
        GIOPSendBuffer *buf = giop_send_buffer_use (giop_version);
 
57
        struct iovec zerovec;
 
58
 
 
59
        if(!principal_vec) {
 
60
                zerovec.iov_base = (gpointer) giop_zero_buf;
 
61
                zerovec.iov_len = sizeof (CORBA_unsigned_long);
 
62
                principal_vec = &zerovec;
 
63
        }
 
64
 
 
65
        buf->msg.header.message_type = GIOP_REQUEST;
 
66
        giop_send_buffer_align (buf, sizeof(CORBA_unsigned_long));
 
67
 
 
68
        switch (giop_version) {
 
69
        case GIOP_1_0:
 
70
        case GIOP_1_1:
 
71
                buf->msg.u.request_1_0.request_id = request_id;
 
72
                buf->msg.u.request_1_0.response_expected = response_expected;
 
73
 
 
74
                giop_send_buffer_append (buf, (const guchar *)iop_service_context_data, sizeof(iop_service_context_data));
 
75
                giop_send_buffer_append (buf, &buf->msg.u.request_1_0.request_id, sizeof(CORBA_unsigned_long));
 
76
                giop_send_buffer_append (buf, &buf->msg.u.request_1_0.response_expected, sizeof(CORBA_boolean));
 
77
                giop_send_buffer_append_aligned (buf, &objkey->_length, sizeof(CORBA_unsigned_long));
 
78
                giop_send_buffer_append (buf, objkey->_buffer, objkey->_length);
 
79
                giop_send_buffer_align (buf, sizeof(CORBA_unsigned_long));
 
80
                giop_send_buffer_append (buf, operation_vec->iov_base, operation_vec->iov_len);
 
81
                giop_send_buffer_append (buf, principal_vec->iov_base, principal_vec->iov_len);
 
82
                break;
 
83
 
 
84
        case GIOP_1_2:
 
85
                buf->msg.u.request_1_2.request_id = request_id;
 
86
                buf->msg.u.request_1_2.response_flags = response_expected ? 0x3 /* SYNC_WITH_TARGET */ : 0x0 /* SYNC_NONE */;
 
87
 
 
88
                giop_send_buffer_align (buf, sizeof(CORBA_unsigned_long));
 
89
                giop_send_buffer_append (buf, &buf->msg.u.request_1_2.request_id, sizeof(CORBA_unsigned_long));
 
90
                giop_send_buffer_append (buf, &buf->msg.u.request_1_2.response_flags, sizeof(CORBA_octet));
 
91
                giop_send_buffer_append (buf, giop_zero_buf, 3);
 
92
                giop_send_buffer_append (buf, &giop_1_2_target_type, 2); /* We always use GIOP::KeyAddr addressing - the only sane way */
 
93
                giop_send_buffer_append_aligned (buf, &objkey->_length, sizeof(CORBA_unsigned_long));
 
94
                giop_send_buffer_append (buf, objkey->_buffer, objkey->_length);
 
95
                giop_send_buffer_align (buf, sizeof(CORBA_unsigned_long));
 
96
                giop_send_buffer_append (buf, operation_vec->iov_base, operation_vec->iov_len);
 
97
                giop_send_buffer_append (buf, (const guchar *)iop_service_context_data, sizeof(iop_service_context_data));
 
98
                giop_send_buffer_align (buf, 8); /* alignment for the body */
 
99
        default:
 
100
                break;
 
101
        }
 
102
 
 
103
        return buf;
93
104
}
94
105
 
95
106
GIOPSendBuffer *
195
206
void
196
207
giop_send_buffer_unuse (GIOPSendBuffer *buf)
197
208
{
198
 
        LINC_MUTEX_LOCK (send_buffer_list_lock);
 
209
        int i;
 
210
 
 
211
        for (i = 0; i < buf->num_indirects_used; i++) {
 
212
                if (buf->indirects[i].size > GIOP_CHUNK_SIZE) {
 
213
                        buf->indirects [i].size = GIOP_CHUNK_SIZE;
 
214
                        buf->indirects [i].ptr = g_realloc (buf->indirects [i].ptr,
 
215
                                                            buf->indirects [i].size);
 
216
                }
 
217
        }
 
218
 
 
219
        LINK_MUTEX_LOCK (send_buffer_list_lock);
199
220
        send_buffer_list = g_slist_prepend (send_buffer_list, buf);
200
 
        LINC_MUTEX_UNLOCK (send_buffer_list_lock);
 
221
 
 
222
        LINK_MUTEX_UNLOCK (send_buffer_list_lock);
201
223
}
202
224
 
203
225
static void
235
257
 
236
258
/*
237
259
 * get_next_indirect:
238
 
 * @buf: the recv buffer with an exhausted indirect.
 
260
 * @buf: the send buffer with an exhausted indirect.
239
261
 * @for_size_hint: for very large buffers specify this
240
262
 * so we don't allocate too much. If this is non 0 then
241
263
 * buf->indirect will contain at least this much space.
264
286
                        new_size = GIOP_CHUNK_SIZE;
265
287
 
266
288
                buf->indirects [max].size = new_size;
267
 
                buf->indirects [max].ptr = g_malloc (new_size);
 
289
 
 
290
                if (giop_blank_wire_data)
 
291
                        buf->indirects [max].ptr = g_malloc0 (new_size);
 
292
                else
 
293
                        buf->indirects [max].ptr = g_malloc (new_size);
 
294
 
 
295
                /*
 
296
                 *   We assume that this is 8 byte aligned, for efficiency -
 
297
                 * so we can align to the memory address rather than the offset
 
298
                 * into the buffer.
 
299
                 */
 
300
                g_assert (((gulong)buf->indirects [max].ptr & 0x3) == 0);
268
301
        }
269
302
 
270
303
        buf->indirect = buf->indirects [max].ptr;
393
426
                        gboolean        blocking)
394
427
{
395
428
        int retval;
396
 
        static LINCWriteOpts *non_block = NULL;
 
429
        static LinkWriteOpts *non_block = NULL;
397
430
 
398
431
        if (!non_block)
399
 
                non_block = linc_write_options_new (FALSE);
400
 
 
401
 
        if (buf->giop_version >= GIOP_1_2)
402
 
                giop_send_buffer_align (buf, 8); /* Do tail align */
403
 
 
404
 
        LINC_MUTEX_LOCK (cnx->outgoing_mutex);
405
 
 
406
 
        retval = linc_connection_writev (
407
 
                (LINCConnection *) cnx, buf->iovecs,
 
432
                non_block = link_write_options_new (FALSE);
 
433
 
 
434
        /* FIXME: if a FRAGMENT, assert the 8 byte tail align,
 
435
           &&|| giop_send_buffer_align (buf, 8); */
 
436
 
 
437
        retval = link_connection_writev (
 
438
                (LinkConnection *) cnx, buf->iovecs,
408
439
                buf->num_used, 
409
440
                blocking ? NULL : non_block);
410
441
 
411
 
        if (!blocking && retval == LINC_IO_QUEUED_DATA)
 
442
        if (!blocking && retval == LINK_IO_QUEUED_DATA)
412
443
                retval = 0;
413
444
 
414
445
        /* FIXME: we need to flag the connection disconnected on fatal error */
415
446
 
416
 
        LINC_MUTEX_UNLOCK (cnx->outgoing_mutex);
417
 
 
418
447
        return retval;
419
448
}
420
449
 
422
451
GIOPSendBuffer *
423
452
giop_send_buffer_use (GIOPVersion giop_version)
424
453
{
425
 
        GIOPSendBuffer *retval;
426
 
 
427
 
        LINC_MUTEX_LOCK (send_buffer_list_lock);
 
454
        GIOPSendBuffer *buf;
 
455
 
 
456
        g_return_val_if_fail (
 
457
                ((int) giop_version) >= 0 &&
 
458
                giop_version < GIOP_NUM_VERSIONS, NULL);
 
459
 
 
460
        LINK_MUTEX_LOCK (send_buffer_list_lock);
428
461
        if (send_buffer_list) {
429
462
                GSList *ltmp;
430
463
 
432
465
                send_buffer_list = g_slist_remove_link (
433
466
                        send_buffer_list, ltmp);
434
467
 
435
 
                LINC_MUTEX_UNLOCK (send_buffer_list_lock);
 
468
                LINK_MUTEX_UNLOCK (send_buffer_list_lock);
436
469
 
437
 
                retval = ltmp->data;
 
470
                buf = ltmp->data;
438
471
                g_slist_free_1 (ltmp);
439
 
                retval->num_used = retval->indirect_left = 0;
440
 
                retval->num_indirects_used = 0;
 
472
                buf->num_used = buf->indirect_left = 0;
 
473
 
 
474
                if (giop_blank_wire_data) {
 
475
                        int i;
 
476
 
 
477
                        for (i = 0; i < buf->num_indirects_used; i++)
 
478
                                memset (buf->indirects [i].ptr, 0,
 
479
                                        buf->indirects [i].size);
 
480
                }
 
481
 
 
482
                buf->num_indirects_used = 0;
441
483
        } else {
442
 
                LINC_MUTEX_UNLOCK (send_buffer_list_lock);
443
 
 
444
 
                retval = g_new0 (GIOPSendBuffer, 1);
445
 
 
446
 
                memcpy (retval->msg.header.magic, "GIOP", 4);
447
 
                retval->msg.header.flags = GIOP_FLAG_ENDIANNESS;
448
 
                retval->num_alloced = 8;
449
 
                retval->iovecs = g_new (struct iovec, 8);
 
484
                LINK_MUTEX_UNLOCK (send_buffer_list_lock);
 
485
 
 
486
                buf = g_new0 (GIOPSendBuffer, 1);
 
487
 
 
488
                memcpy (buf->msg.header.magic, "GIOP", 4);
 
489
                buf->msg.header.flags = GIOP_FLAG_ENDIANNESS;
 
490
                buf->num_alloced = 8;
 
491
                buf->iovecs = g_new (struct iovec, 8);
450
492
        }
451
493
 
452
 
        memcpy (retval->msg.header.version,
 
494
 
 
495
        memcpy (buf->msg.header.version,
453
496
                giop_version_ids [giop_version], 2);
454
 
        retval->giop_version = giop_version;
 
497
        buf->giop_version = giop_version;
455
498
 
456
 
        g_assert (sizeof (retval->msg.header) == 12);
 
499
        g_assert (sizeof (buf->msg.header) == 12);
457
500
        giop_send_buffer_append_real (
458
 
                retval, (guchar *)&retval->msg.header, 12);
459
 
 
460
 
        retval->msg.header.message_size = 0;
461
 
        retval->header_size = 12;
462
 
 
463
 
        return retval;
 
501
                buf, (guchar *)&buf->msg.header, 12);
 
502
 
 
503
        buf->msg.header.message_size = 0;
 
504
        buf->header_size = 12;
 
505
 
 
506
        return buf;
464
507
}
465
508
 
466
509
void