OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_c/] [synfull/] [pronoc-interface/] [netstream/] [socketstream.h] - Blame information for rev 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 54 alirezamon
/*
2
 * socketstream.h
3
 *
4
 *  Created on: Dec 14, 2009
5
 *      Author: sam
6
 */
7
 
8
#ifndef SOCKETSTREAM_H_
9
#define SOCKETSTREAM_H_
10
 
11
#include <iostream>
12
 
13
#include <unistd.h>
14
#include <sys/types.h>
15
#include <sys/un.h>
16
#include <stdlib.h>
17
#include <sys/socket.h>
18
#include <arpa/inet.h>
19
#include <netdb.h>
20
#include <netinet/tcp.h>
21
 
22
#include <cstring>
23
 
24
#define NS_DEBUG
25
// #define NS_DEBUG_EXTRA
26
#define NS_MAX_PENDING 1
27
#define NS_HOST "local"
28
#define NS_PORT 0
29
 
30
using namespace std;
31
 
32
class SocketStream
33
{
34
public:
35
        int so; // the socket
36
        struct sockaddr_un addr;
37
        bool bIsAlive;
38
 
39
public:
40
 
41
        SocketStream() : so(-1), bIsAlive(false)
42
        {
43
        }
44
 
45
        // create from an existing socket
46
        SocketStream(int sock) : so(sock), bIsAlive(true)
47
        {
48
        }
49
 
50
        ~SocketStream()
51
        {
52
                if (so != -1)
53
                {
54
                        close(so);
55
                }
56
        }
57
 
58
        SocketStream(int sock, struct sockaddr *in_addr, socklen_t in_addrlen)
59
        {
60
                so = sock;
61
                bIsAlive = true;
62
                memcpy(&addr, in_addr, in_addrlen);
63
        }
64
 
65
        int listen(const char *host, int port);
66
 
67
        SocketStream* accept();
68
 
69
        int connect(const char *host, int port);
70
 
71
    // read from the socket
72
    int get(void *data, int number);
73
 
74
    // write to socket
75
    int put(const void *data, int number);
76
 
77
        bool isAlive()
78
        {
79
                return bIsAlive;
80
        }
81
 
82
};
83
 
84
#endif /* SOCKETSTREAM_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.