~ubuntu-branches/ubuntu/utopic/jetty/utopic-proposed

« back to all changes in this revision

Viewing changes to modules/jetty/src/main/java/org/mortbay/io/nio/ChannelEndPoint.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2010-04-29 07:36:43 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429073643-eo2x6y2fit4m6o66
Tags: 6.1.24-2
* Set JAVA_HOME in d/rules to /usr/lib/jvm/default-java. (Closes: #578618,
  #579469)
* Fix the installation of jetty-util5.jar. (Closes: #569328)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
//------------------------------------------------------------------------
5
5
//Licensed under the Apache License, Version 2.0 (the "License");
6
6
//you may not use this file except in compliance with the License.
7
 
//You may obtain a copy of the License at 
 
7
//You may obtain a copy of the License at
8
8
//http://www.apache.org/licenses/LICENSE-2.0
9
9
//Unless required by applicable law or agreed to in writing, software
10
10
//distributed under the License is distributed on an "AS IS" BASIS,
43
43
    protected Socket _socket;
44
44
    protected InetSocketAddress _local;
45
45
    protected InetSocketAddress _remote;
46
 
    
 
46
 
47
47
    /**
48
 
     * 
 
48
     *
49
49
     */
50
50
    public ChannelEndPoint(ByteChannel channel)
51
51
    {
54
54
        if (channel instanceof SocketChannel)
55
55
            _socket=((SocketChannel)channel).socket();
56
56
    }
57
 
    
 
57
 
58
58
    public boolean isBlocking()
59
59
    {
60
60
        if (_channel instanceof SelectableChannel)
61
61
            return ((SelectableChannel)_channel).isBlocking();
62
62
        return true;
63
63
    }
64
 
    
 
64
 
65
65
    public boolean blockReadable(long millisecs) throws IOException
66
66
    {
67
67
        return true;
68
68
    }
69
 
    
 
69
 
70
70
    public boolean blockWritable(long millisecs) throws IOException
71
71
    {
72
72
        return true;
73
73
    }
74
74
 
75
 
    /* 
 
75
    /*
76
76
     * @see org.mortbay.io.EndPoint#isOpen()
77
77
     */
78
78
    public boolean isOpen()
143
143
        {
144
144
            throw new IOException("Not Implemented");
145
145
        }
146
 
        
 
146
 
147
147
        return len;
148
148
    }
149
149
 
159
159
            NIOBuffer nbuf = (NIOBuffer)buf;
160
160
            ByteBuffer bbuf=nbuf.getByteBuffer();
161
161
 
162
 
            // TODO synchronize 
 
162
            // TODO synchronize
163
163
            synchronized(bbuf)
164
164
            {
165
165
                try
200
200
 
201
201
        Buffer buf0 = header==null?null:header.buffer();
202
202
        Buffer buf1 = buffer==null?null:buffer.buffer();
203
 
        
 
203
 
204
204
        if (_channel instanceof GatheringByteChannel &&
205
 
            header!=null && header.length()!=0 && header instanceof NIOBuffer && 
 
205
            header!=null && header.length()!=0 && header instanceof NIOBuffer &&
206
206
            buffer!=null && buffer.length()!=0 && buffer instanceof NIOBuffer)
207
207
        {
208
208
            NIOBuffer nbuf0 = (NIOBuffer)buf0;
241
241
                            {
242
242
                                header.skip(length);
243
243
                            }
244
 
                            
 
244
 
245
245
                        }
246
246
                        finally
247
247
                        {
262
262
        }
263
263
        else
264
264
        {
265
 
            // TODO - consider copying buffers buffer and trailer into header if there is space!
266
 
            
 
265
            if (header!=null)
 
266
            {
 
267
                if (buffer!=null && buffer.length()>0 && header.space()>buffer.length())
 
268
                {
 
269
                    header.put(buffer);
 
270
                    buffer.clear();
 
271
                }
 
272
                if (trailer!=null && trailer.length()>0 && header.space()>trailer.length())
 
273
                {
 
274
                    header.put(trailer);
 
275
                    trailer.clear();
 
276
                }
 
277
            }
 
278
 
267
279
            // flush header
268
280
            if (header!=null && header.length()>0)
269
281
                length=flush(header);
279
291
                 trailer!=null && trailer.length()>0)
280
292
                length+=flush(trailer);
281
293
        }
282
 
        
 
294
 
283
295
        return length;
284
296
    }
285
297
 
293
305
 
294
306
 
295
307
    /* ------------------------------------------------------------ */
296
 
    /* 
 
308
    /*
297
309
     * @see org.mortbay.io.EndPoint#getLocalAddr()
298
310
     */
299
311
    public String getLocalAddr()
300
312
    {
301
313
        if (_socket==null)
302
314
            return null;
303
 
        
 
315
 
304
316
        if (_local==null)
305
317
            _local=(InetSocketAddress)_socket.getLocalSocketAddress();
306
 
        
 
318
 
307
319
       if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
308
320
           return Portable.ALL_INTERFACES;
309
 
        
 
321
 
310
322
        return _local.getAddress().getHostAddress();
311
323
    }
312
324
 
313
325
    /* ------------------------------------------------------------ */
314
 
    /* 
 
326
    /*
315
327
     * @see org.mortbay.io.EndPoint#getLocalHost()
316
328
     */
317
329
    public String getLocalHost()
318
330
    {
319
331
        if (_socket==null)
320
332
            return null;
321
 
        
 
333
 
322
334
        if (_local==null)
323
335
            _local=(InetSocketAddress)_socket.getLocalSocketAddress();
324
 
        
 
336
 
325
337
       if (_local==null || _local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
326
338
           return Portable.ALL_INTERFACES;
327
 
        
 
339
 
328
340
        return _local.getAddress().getCanonicalHostName();
329
341
    }
330
342
 
331
343
    /* ------------------------------------------------------------ */
332
 
    /* 
 
344
    /*
333
345
     * @see org.mortbay.io.EndPoint#getLocalPort()
334
346
     */
335
347
    public int getLocalPort()
336
348
    {
337
349
        if (_socket==null)
338
350
            return 0;
339
 
        
 
351
 
340
352
        if (_local==null)
341
353
            _local=(InetSocketAddress)_socket.getLocalSocketAddress();
342
354
        if (_local==null)
345
357
    }
346
358
 
347
359
    /* ------------------------------------------------------------ */
348
 
    /* 
 
360
    /*
349
361
     * @see org.mortbay.io.EndPoint#getRemoteAddr()
350
362
     */
351
363
    public String getRemoteAddr()
352
364
    {
353
365
        if (_socket==null)
354
366
            return null;
355
 
        
 
367
 
356
368
        if (_remote==null)
357
369
            _remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
358
 
        
 
370
 
359
371
        if (_remote==null)
360
372
            return null;
361
373
        return _remote.getAddress().getHostAddress();
362
374
    }
363
375
 
364
376
    /* ------------------------------------------------------------ */
365
 
    /* 
 
377
    /*
366
378
     * @see org.mortbay.io.EndPoint#getRemoteHost()
367
379
     */
368
380
    public String getRemoteHost()
369
381
    {
370
382
        if (_socket==null)
371
383
            return null;
372
 
        
 
384
 
373
385
        if (_remote==null)
374
386
            _remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
375
387
 
379
391
    }
380
392
 
381
393
    /* ------------------------------------------------------------ */
382
 
    /* 
 
394
    /*
383
395
     * @see org.mortbay.io.EndPoint#getRemotePort()
384
396
     */
385
397
    public int getRemotePort()
386
398
    {
387
399
        if (_socket==null)
388
400
            return 0;
389
 
        
 
401
 
390
402
        if (_remote==null)
391
403
            _remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
392
404
 
396
408
    }
397
409
 
398
410
    /* ------------------------------------------------------------ */
399
 
    /* 
 
411
    /*
400
412
     * @see org.mortbay.io.EndPoint#getConnection()
401
413
     */
402
414
    public Object getTransport()
407
419
    /* ------------------------------------------------------------ */
408
420
    public void flush()
409
421
        throws IOException
410
 
    {   
 
422
    {
411
423
    }
412
424
 
413
425
    /* ------------------------------------------------------------ */