File: UDPSocket.cpp

package info (click to toggle)
libassa 3.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,268 kB
  • sloc: cpp: 15,703; sh: 12,083; makefile: 379; perl: 51
file content (66 lines) | stat: -rw-r--r-- 1,420 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// -*- c++ -*-
//------------------------------------------------------------------------------
//                             UDPSocket.C
//------------------------------------------------------------------------------
//  Copyright (c) 2000 by Vladislav Grinchenko
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Library General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//------------------------------------------------------------------------------
//  Created: 03/22/99
//------------------------------------------------------------------------------

#include "assa/UDPSocket.h"

using namespace ASSA;

bool 
UDPSocket::
open (const int domain_)
{
	trace("UDPSocket::open");

	m_type = domain_;
	m_fd = ::socket (m_type, SOCK_DGRAM, 0);

	if (m_fd < 0) {
		setstate (Socket::failbit);
		return false;
	}
	clear ();
	return true;
}

bool 
UDPSocket::
close ()
{
	trace("UDPSocket::close()");
	if ( m_fd >= 0 ) {
		::close(m_fd);
		setstate (Socket::failbit);
		m_fd = -1;
	}
	return true;
}

bool 
UDPSocket::
bind (const Address& my_address_)
{
	trace("UDPSocket::bind");

	int ret = ::bind (m_fd, (SA*) my_address_.getAddress(),
			  my_address_.getLength());
	if (ret < 0) {
		setstate (Socket::failbit);
		return false;
	}
	return true;
}