Ejemplo n.º 1
0
func createUnixSocket(addr *net.UnixAddr) (l net.Listener, err error) {
	l, err = net.ListenUnix("unix", addr)

	if err != nil {
		return
	}

	// TODO(lcooper): Not sure if this sequence is completely safe.
	// It would be better if we could get the underlying FD of the socket
	// and stat() + chmod() that instead.
	fi, err := os.Stat(addr.String())
	if err != nil {
		return
	}

	// NOTE(lcooper): This only ensures g+w other then on Linux,
	// BSD systems only use parent directory permissions.
	// See http://stackoverflow.com/questions/5977556 .
	err = os.Chmod(addr.String(), fi.Mode()|0060)
	return
}
Ejemplo n.º 2
0
//Threaded, Asynchronous approach to sorting list.
//for the given rpc client, send a portion of the given list list1
//to said client to sort and return.
func SortClient(m1 *[]int, l1 *[]int, list1 *[]int, val string, i int, clientSize int, c chan []int) {

	l2 := *l1
	m := *m1
	//	list := *list1

	defer close(c)

	var err error

	checkError(err)

	client := new(rpc.Client)

	if *protocolFlag == "tcp" {
		//		fmt.Println("Attempting connection to tcp:", val)
		client, err = rpc.DialHTTP("tcp", val)
	} else {
		var unixAddr *net.UnixAddr
		unixAddr, err = net.ResolveUnixAddr("unix", val)
		fmt.Println("Attempting connection to socket:", val)
		fmt.Println(unixAddr)
		//			client, err = rpc.Dial("unix", unixAddr.String())
		c2, err := net.Dial("unix", unixAddr.String())
		checkError(err)

		fmt.Println("Successfully Connected to Unix Port", c2)
	}

	if err != nil {
		log.Fatal("dialing:", err)
	}

	//compensates for remainders when the
	//len(m)%(# of clients) != 0
	remainder := len(m) % clientSize
	start, end := 0, 0

	if remainder > 0 && i < remainder {
		start, end = (len(m)/(clientSize))*i+i, (len(m)/(clientSize))*(i+1)+i
	} else {
		start, end = (len(m)/(clientSize))*i, (len(m)/(clientSize))*(i+1)-1
		start, end = start+remainder, end+remainder
	}

	fmt.Println("Sorting List", start, end)

	l2 = make([]int, end-start+1)
	for j := start; j < end; j++ {
		l2[j-start] = m[j]
	}

	s := ""

	err = client.Call("Util.SetThreads", 4, &s)
	fmt.Println(s)

	r := new(utility.Reply)
	err = client.Call("Util.Sort", l2, &r)

	fmt.Println("Client Returned ", len(r.Data))
	//
	//	list = make([]int, len(r.Data))
	//
	for j, val := range r.Data {
		//?		list[j] = val
		l2[j] = val
	}

	if err != nil {
		log.Fatal("util error error:", err)
	}

	client.Close()

	c <- l2

}