~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/vm/jvm/runtime/org/perl6/nqp/io/SocketHandle.java

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.perl6.nqp.io;
 
2
 
 
3
import java.io.IOException;
 
4
import java.net.InetSocketAddress;
 
5
import java.nio.channels.SocketChannel;
 
6
import java.nio.charset.Charset;
 
7
 
 
8
import org.perl6.nqp.runtime.ExceptionHandling;
 
9
import org.perl6.nqp.runtime.ThreadContext;
 
10
 
 
11
public class SocketHandle extends SyncHandle {
 
12
 
 
13
    public SocketHandle(ThreadContext tc) {
 
14
        try {
 
15
            chan = SocketChannel.open();
 
16
            setEncoding(tc, Charset.forName("UTF-8"));
 
17
        } catch (IOException e) {
 
18
            throw ExceptionHandling.dieInternal(tc, e);
 
19
        }
 
20
    }
 
21
    
 
22
    public SocketHandle(ThreadContext tc, SocketChannel existing) {
 
23
        chan = existing;
 
24
        setEncoding(tc, Charset.forName("UTF-8"));
 
25
    }
 
26
    
 
27
    public void connect(ThreadContext tc, String host, int port) {
 
28
        try {
 
29
            InetSocketAddress addr = new InetSocketAddress(host, port);
 
30
            ((SocketChannel)chan).connect(addr);
 
31
        } catch (IOException e) {
 
32
            throw ExceptionHandling.dieInternal(tc, e);
 
33
        }
 
34
    }
 
35
    
 
36
    public void flush(ThreadContext tc) {
 
37
        // Not provided.
 
38
    }
 
39
}