~ubuntu-branches/debian/jessie/italc/jessie

« back to all changes in this revision

Viewing changes to ica/x11/libvncserver/rfbserver.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2011-02-11 14:50:22 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20110211145022-sn173siax6lywjus
Tags: upstream-1.0.13
ImportĀ upstreamĀ versionĀ 1.0.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
#endif
55
55
#endif
56
56
 
57
 
#ifdef CORBA
58
 
#include <vncserverctrl.h>
59
 
#endif
60
 
 
61
57
#ifdef DEBUGPROTO
62
58
#undef DEBUGPROTO
63
59
#define DEBUGPROTO(x) x
214
210
    rfbClientPtr cl;
215
211
 
216
212
    cl = rfbNewClient(rfbScreen,sock);
217
 
#ifdef CORBA
218
 
    if(cl!=NULL)
219
 
      newConnection(cl, (KEYBOARD_DEVICE|POINTER_DEVICE),1,1,1);
220
 
#endif
221
213
}
222
214
 
223
215
 
224
216
/*
225
 
 * rfbReverseConnection is called by the CORBA stuff to make an outward
 
217
 * rfbReverseConnection is called to make an outward
226
218
 * connection to a "listening" RFB client.
227
219
 */
228
220
 
307
299
      }
308
300
      rfbReleaseClientIterator(iterator);
309
301
 
310
 
#ifndef WIN32
311
 
      if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
312
 
        rfbLogPerror("fcntl failed");
 
302
      if(!rfbSetNonBlocking(sock)) {
313
303
        close(sock);
314
304
        return NULL;
315
305
      }
316
 
#endif
317
306
 
318
307
      if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
319
308
                     (char *)&one, sizeof(one)) < 0) {
327
316
 
328
317
      INIT_MUTEX(cl->outputMutex);
329
318
      INIT_MUTEX(cl->refCountMutex);
 
319
      INIT_MUTEX(cl->sendMutex);
330
320
      INIT_COND(cl->deleteCond);
331
321
 
332
322
      cl->state = RFB_PROTOCOL_VERSION;
484
474
    if (cl->next)
485
475
        cl->next->prev = cl->prev;
486
476
 
487
 
    if(cl->sock>0)
 
477
    if(cl->sock>=0)
488
478
        close(cl->sock);
489
479
 
490
480
    if (cl->scaledScreen!=NULL)
550
540
    UNLOCK(cl->outputMutex);
551
541
    TINI_MUTEX(cl->outputMutex);
552
542
 
553
 
#ifdef CORBA
554
 
    destroyConnection(cl);
555
 
#endif
 
543
    LOCK(cl->sendMutex);
 
544
    UNLOCK(cl->sendMutex);
 
545
    TINI_MUTEX(cl->sendMutex);
556
546
 
557
547
    rfbPrintStats(cl);
558
548
 
1102
1092
    /*
1103
1093
    rfbLog("rfbSendFileTransferMessage( %dtype, %dparam, %dsize, %dlen, %p)\n", contentType, contentParam, size, length, buffer);
1104
1094
    */
 
1095
    LOCK(cl->sendMutex);
1105
1096
    if (rfbWriteExact(cl, (char *)&ft, sz_rfbFileTransferMsg) < 0) {
1106
1097
        rfbLogPerror("rfbSendFileTransferMessage: write");
1107
1098
        rfbCloseClient(cl);
 
1099
        UNLOCK(cl->sendMutex);
1108
1100
        return FALSE;
1109
1101
    }
1110
1102
 
1113
1105
        if (rfbWriteExact(cl, buffer, length) < 0) {
1114
1106
            rfbLogPerror("rfbSendFileTransferMessage: write");
1115
1107
            rfbCloseClient(cl);
 
1108
            UNLOCK(cl->sendMutex);
1116
1109
            return FALSE;
1117
1110
        }
1118
1111
    }
 
1112
    UNLOCK(cl->sendMutex);
1119
1113
 
1120
1114
    rfbStatRecordMessageSent(cl, rfbFileTransfer, sz_rfbFileTransferMsg+length, sz_rfbFileTransferMsg+length);
1121
1115
 
1525
1519
 
1526
1520
        /* TODO: finish 64-bit file size support */
1527
1521
        sizeHtmp = 0;        
 
1522
        LOCK(cl->sendMutex);
1528
1523
        if (rfbWriteExact(cl, (char *)&sizeHtmp, 4) < 0) {
1529
1524
          rfbLogPerror("rfbProcessFileTransfer: write");
1530
1525
          rfbCloseClient(cl);
 
1526
          UNLOCK(cl->sendMutex);
1531
1527
          if (buffer!=NULL) free(buffer);
1532
1528
          return FALSE;
1533
1529
        }
 
1530
        UNLOCK(cl->sendMutex);
1534
1531
        break;
1535
1532
 
1536
1533
    case rfbFileHeader:
2122
2119
            if (!cl->format.trueColour) {
2123
2120
                if (!rfbSetClientColourMap(cl, 0, 0)) {
2124
2121
                    sraRgnDestroy(tmpRegion);
 
2122
                    TSIGNAL(cl->updateCond);
2125
2123
                    UNLOCK(cl->updateMutex);
2126
2124
                    return;
2127
2125
                }
2433
2431
      fu->nRects = Swap16IfLE(1);
2434
2432
      cl->ublen = sz_rfbFramebufferUpdateMsg;
2435
2433
      if (!rfbSendNewFBSize(cl, cl->scaledScreen->width, cl->scaledScreen->height)) {
 
2434
        if(cl->screen->displayFinishedHook)
 
2435
          cl->screen->displayFinishedHook(cl, FALSE);
2436
2436
        return FALSE;
2437
2437
      }
2438
 
      return rfbSendUpdateBuf(cl);
 
2438
      result = rfbSendUpdateBuf(cl);
 
2439
      if(cl->screen->displayFinishedHook)
 
2440
        cl->screen->displayFinishedHook(cl, result);
 
2441
      return result;
2439
2442
    }
2440
2443
    
2441
2444
    /*
2551
2554
       !sendSupportedMessages && !sendSupportedEncodings && !sendServerIdentity) {
2552
2555
      sraRgnDestroy(updateRegion);
2553
2556
      UNLOCK(cl->updateMutex);
 
2557
      if(cl->screen->displayFinishedHook)
 
2558
        cl->screen->displayFinishedHook(cl, TRUE);
2554
2559
      return TRUE;
2555
2560
    }
2556
2561
 
2828
2833
        sraRgnReleaseIterator(i);
2829
2834
    sraRgnDestroy(updateRegion);
2830
2835
    sraRgnDestroy(updateCopyRegion);
 
2836
 
 
2837
    if(cl->screen->displayFinishedHook)
 
2838
      cl->screen->displayFinishedHook(cl, result);
2831
2839
    return result;
2832
2840
}
2833
2841
 
3103
3111
 
3104
3112
    len += nColours * 3 * 2;
3105
3113
 
 
3114
    LOCK(cl->sendMutex);
3106
3115
    if (rfbWriteExact(cl, wbuf, len) < 0) {
3107
3116
        rfbLogPerror("rfbSendSetColourMapEntries: write");
3108
3117
        rfbCloseClient(cl);
3109
3118
        if (wbuf != buf) free(wbuf);
 
3119
        UNLOCK(cl->sendMutex);
3110
3120
        return FALSE;
3111
3121
    }
 
3122
    UNLOCK(cl->sendMutex);
3112
3123
 
3113
3124
    rfbStatRecordMessageSent(cl, rfbSetColourMapEntries, len, len);
3114
3125
    if (wbuf != buf) free(wbuf);
3129
3140
    i = rfbGetClientIterator(rfbScreen);
3130
3141
    while((cl=rfbClientIteratorNext(i))) {
3131
3142
        b.type = rfbBell;
 
3143
        LOCK(cl->sendMutex);
3132
3144
        if (rfbWriteExact(cl, (char *)&b, sz_rfbBellMsg) < 0) {
3133
3145
            rfbLogPerror("rfbSendBell: write");
3134
3146
            rfbCloseClient(cl);
3135
3147
        }
 
3148
        UNLOCK(cl->sendMutex);
3136
3149
    }
3137
3150
    rfbStatRecordMessageSent(cl, rfbBell, sz_rfbBellMsg, sz_rfbBellMsg);
3138
3151
    rfbReleaseClientIterator(i);
3154
3167
    while ((cl = rfbClientIteratorNext(iterator)) != NULL) {
3155
3168
        sct.type = rfbServerCutText;
3156
3169
        sct.length = Swap32IfLE(len);
 
3170
        LOCK(cl->sendMutex);
3157
3171
        if (rfbWriteExact(cl, (char *)&sct,
3158
3172
                       sz_rfbServerCutTextMsg) < 0) {
3159
3173
            rfbLogPerror("rfbSendServerCutText: write");
3160
3174
            rfbCloseClient(cl);
 
3175
            UNLOCK(cl->sendMutex);
3161
3176
            continue;
3162
3177
        }
3163
3178
        if (rfbWriteExact(cl, str, len) < 0) {
3164
3179
            rfbLogPerror("rfbSendServerCutText: write");
3165
3180
            rfbCloseClient(cl);
3166
3181
        }
 
3182
        UNLOCK(cl->sendMutex);
3167
3183
        rfbStatRecordMessageSent(cl, rfbServerCutText, sz_rfbServerCutTextMsg+len, sz_rfbServerCutTextMsg+len);
3168
3184
    }
3169
3185
    rfbReleaseClientIterator(iterator);