Пример #1
0
func createSessionCookie(w http.ResponseWriter, user string) (session string) {
	session = fmt.Sprintf("s%v", rand.Int31())
	value := encodeSecureCookie(user, session, time.UTC().Seconds())
	// Cookie
	cookie := &http.Cookie{Path: "/", Name: "Session", Value: value, Expires: *time.SecondsToUTC(time.UTC().Seconds() + maxAge)}
	http.SetCookie(w, cookie)
	return
}
Пример #2
0
func (self *Connection) sendMessage(m message) os.Error {
	body := m.Bytes()
	h := header(msgHeader{int32(len(body) + _HEADER_SIZE), rand.Int31(), 0, m.OpCode()})

	msg := append(h, body...)
	_, err := self.conn.Write(msg)

	return err
}
func main() {
	a := make([]int32, 30000)
	for i := 0; i < 30000; i++ {
		a[i] = rand.Int31()
	}
	done := make(chan int)
	go merge_sort(a, done)
	<-done
}
Пример #4
0
func generateTests(iterations int) []VarInt {
	t := make([]VarInt, iterations)
	for idx := 0; idx < iterations; idx++ {
		v := VarInt(rand.Int31())
		t = append(t, v)
	}

	return t
}
Пример #5
0
/* Gets a random request identifier different to the last one.

To check anytime the server is sending a response ('opQuery', 'opGetMore').
*/
func getRequestID() int32 {
	id := rand.Int31()

	if id == lastRequestID {
		return getRequestID()
	}
	lastRequestID = id

	return id
}
Пример #6
0
func (c *Cursor) Close() os.Error {
	if c.id == 0 {
		// not open on server
		return nil
	}

	req_id := rand.Int31()
	km := &killMsg{1, []int64{c.id}, req_id}
	conn := c.collection.db.conn
	return conn.writeMessage(km)
}
Пример #7
0
func (coll *Collection) Query(query BSON, skip, limit int) (*Cursor, os.Error) {
	req_id := rand.Int31()
	conn := coll.db.conn
	qm := &queryMsg{0, coll.fullName(), int32(skip), int32(limit), query, req_id}

	err := conn.writeMessage(qm)
	if err != nil {
		return nil, err
	}

	reply, err := conn.readReply()
	if err != nil {
		return nil, err
	}
	if reply.responseTo != req_id {
		return nil, os.NewError("wrong responseTo code")
	}

	return &Cursor{coll, reply.cursorID, 0, reply.docs}, nil
}
Пример #8
0
func (c *Cursor) GetMore() os.Error {
	if c.id == 0 {
		return os.NewError("no cursorID")
	}

	gm := &getMoreMsg{c.collection.fullName(), 0, c.id, rand.Int31()}
	conn := c.collection.db.conn
	err := conn.writeMessage(gm)
	if err != nil {
		return err
	}

	reply, err := conn.readReply()
	if err != nil {
		return err
	}

	c.pos = 0
	c.docs = reply.docs

	return nil
}
Пример #9
0
func queryRoleLogin1(cli *mysql.Client) {
	queryName := "[RoleLogin.query1]"
	loopCount := 1000
	type row struct {
		// PK: (date, server, roleid)
		date   string
		server int8
		roleid int64
		money  int32
	}
	fmt.Println(queryName, "started...")
	startTime := time.Nanoseconds()
	for i := 0; i < loopCount; i++ {
		newRow := &row{}
		newRow.date = fmt.Sprintf("2011-%02d-%02d %02d:%02d:%02d",
			rand.Intn(12)+1, // month
			rand.Intn(30)+1, // day
			rand.Intn(24),   // hour
			rand.Intn(60),   // minute
			rand.Intn(60))   // second
		newRow.server = int8(rand.Intn(127))
		newRow.roleid = rand.Int63()
		newRow.money = rand.Int31()
		if VERBOSE_MODE {
			fmt.Printf("%s INSERT IGNORE INTO role_login VALUES(%s, %d, %d, %d)\n",
				queryName, newRow.date, newRow.server, newRow.roleid, newRow.money)
		} else {
			if i == 0 {
				fmt.Printf("%s INSERT IGNORE INTO role_login "+
					"VALUES(%s, %d, %d, %d)\n",
					queryName, newRow.date, newRow.server,
					newRow.roleid, newRow.money)
				fmt.Printf("%s ...(%d lines)\n",
					queryName, loopCount-1)
			}
		}
		if !DRYRUN_MODE {
			cli.Start()
			stmt, err := cli.Prepare("INSERT IGNORE INTO role_login " +
				"VALUES(?,?,?,?)")
			if err != nil {
				fmt.Fprintln(os.Stderr, queryName+err.String())
				os.Exit(1)
			}
			err = stmt.BindParams(newRow.date, newRow.server, newRow.roleid,
				newRow.money)
			if err != nil {
				fmt.Fprintln(os.Stderr, queryName+err.String())
				os.Exit(1)
			}
			err = stmt.Execute()
			if err != nil {
				fmt.Fprintln(os.Stderr, queryName+err.String())
				os.Exit(1)
			}
			cli.Rollback()
		}
		endTime := time.Nanoseconds()
		if !DRYRUN_MODE {
			fmt.Printf("%s ended. Averange query time: %d nanosecs.\n", queryName,
				(endTime-startTime)/((int64)(loopCount)))
		} else {
			fmt.Printf("%s ended.\n", queryName)
		}
	}
}
Пример #10
0
func (coll *Collection) update(um *updateMsg) os.Error {
	um.requestID = rand.Int31()
	conn := coll.db.conn
	return conn.writeMessage(um)
}
Пример #11
0
func (c *Collection) Remove(selector BSON) os.Error {
	dm := &deleteMsg{c.fullName(), selector, rand.Int31()}
	return c.db.conn.writeMessage(dm)
}
Пример #12
0
func (c *Collection) Insert(doc BSON) os.Error {
	im := &insertMsg{c.fullName(), doc, rand.Int31()}
	return c.db.conn.writeMessage(im)
}